import { ServerRoute } from '@hapi/hapi'
import { TestimonialHandler } from '../handlers/testimonial.handler'
import { options } from "../validators/global.validator.schema"
import { Common } from "../../utils/common"
import {
    testimonialResponse,
    testimonialRequest,
    testimonialIdentifier,
    testimonialListRequest,
    testimonialListResponse,
    testimonialListAllRequest,
    testimonialListAllResponse,
    testimonialStatusRequest
} from "../validators/testimonial.validator"
import { I18N } from '../../utils/i18n';
const testimonialHandler = new TestimonialHandler();
import { error400, error401, error403, error404, error500 } from "../validators/global.validator.schema"

const routes: ServerRoute[] = [
    {
        method: 'POST',
        path: '/testimonial',
        handler: testimonialHandler.create,
        options: {
            tags: ['api', 'Testimonial'],
            description: I18N.t('CREATE_TESTIMONIAL_DESCRIPTION'),
            notes: I18N.t('CREATE_TESTIMONIAL_NOTE'),
            auth: { strategies: ['jwt'], scope: ['admin', 'manageTestimonials'] },
            plugins: { 'hapi-swagger': { order: 1 } },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: testimonialRequest,
            },
            response: {
                status: {
                    201: testimonialResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'GET',
        path: '/testimonial/{id}',
        handler: testimonialHandler.getById,
        options: {
            tags: ['api', 'Testimonial'],
            description: I18N.t('GET_TESTIMONIAL_BY_ID_DESCRIPTION'),
            notes: I18N.t('GET_TESTIMONIAL_BY_ID_NOTE'),
            plugins: { 'hapi-swagger': { order: 2 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageTestimonials'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: testimonialIdentifier
            },
            response: {
                status: {
                    200: testimonialResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'PATCH',
        path: '/testimonial/{id}',
        handler: testimonialHandler.update,
        options: {
            tags: ['api', 'Testimonial'],
            description: I18N.t('UPDATE_TESTIMONIAL_DESCRIPTION'),
            notes: I18N.t('UPDATE_TESTIMONIAL_NOTE'),
            plugins: { 'hapi-swagger': { order: 3 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageTestimonials'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: testimonialRequest,
                params: testimonialIdentifier
            },
            response: {
                status: {
                    200: testimonialResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'DELETE',
        path: '/testimonial/{id}',
        handler: testimonialHandler.delete,
        options: {
            tags: ['api', 'Testimonial'],
            description: I18N.t('DELETE_TESTIMONIAL_DESCRIPTION'),
            notes: I18N.t('DELETE_TESTIMONIAL_NOTE'),
            plugins: { 'hapi-swagger': { order: 4 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageTestimonials'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: testimonialIdentifier
            },
            response: {
                status: {
                    200: testimonialResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'GET',
        path: '/testimonial/list',
        handler: testimonialHandler.list,
        options: {
            tags: ['api', 'Testimonial'],
            description: I18N.t('LIST_TESTIMONIAL_DESCRIPTION'),
            notes: I18N.t('LIST_TESTIMONIAL_NOTE'),
            plugins: { 'hapi-swagger': { order: 5 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageTestimonials'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                query: testimonialListRequest
            },
            response: {
                status: {
                    200: testimonialListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'GET',
        path: '/testimonial/listAll',
        handler: testimonialHandler.listAll,
        options: {
            tags: ['api', 'Testimonial'],
            description: I18N.t('LIST_ALL_TESTIMONIAL_DESCRIPTION'),
            notes: I18N.t('LIST_ALL_TESTIMONIAL_NOTE'),
            plugins: { 'hapi-swagger': { order: 6 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageTestimonials'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                query: testimonialListAllRequest
            },
            response: {
                status: {
                    200: testimonialListAllResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'PATCH',
        path: '/testimonial/{id}/status',
        handler: testimonialHandler.updateStatus,
        options: {
            tags: ['api', 'Testimonial'],
            description: I18N.t('TESTIMONIAL_STATUS_UPDATE_DESCRIPTION'),
            notes: I18N.t('TESTIMONIAL_STATUS_UPDATE_NOTE'),
            plugins: { 'hapi-swagger': { order: 7 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageTestimonials'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: testimonialIdentifier,
                payload: testimonialStatusRequest
            },
            response: {
                status: {
                    200: testimonialResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'GET',
        path: '/testimonials',
        handler: testimonialHandler.publicList,
        options: {
            tags: ['api', 'Testimonial'],
            description: I18N.t('LIST_TESTIMONIAL_DESCRIPTION'),
            notes: I18N.t('LIST_TESTIMONIAL_NOTE'),
            plugins: { 'hapi-swagger': { order: 8 } },
            auth: false,
            validate: {
                options: options,
                failAction: Common.failover,
                query: testimonialListRequest
            },
            response: {
                status: {
                    200: testimonialListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    }
]
export default routes
