import { ServerRoute } from '@hapi/hapi'
import Joi from '@hapi/joi'
import { FaqHandler } from '../handlers/faq.handler'
import { options } from "../validators/global.validator.schema"
import { Common } from "../../utils/common"
import {
    faqResponse,
    faqRequest,
    faqIdentifier,
    faqStringIdentifier,
    faqListRequest,
    faqListResponse,
    faqListAllRequest,
    faqListAllResponse,
    faqStatusRequest,
    faqSortOrderRequest,
    faqPublicListRequest
} from "../validators/faq.validator"
import { I18N } from '../../utils/i18n';
const faqHandler = new FaqHandler();
import { error400, error401, error403, error404, error500, confirmationOnly } from "../validators/global.validator.schema"
const routes: ServerRoute[] = [
    {
        method: 'POST',
        path: '/faq',
        handler: faqHandler.create,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('CREATE_FAQ_DESCRIPTION'),
            notes: I18N.t('CREATE_FAQ_NOTE'),
            auth: { strategies: ['jwt'], scope: ['admin', 'manageFaqs'] },
            plugins: { 'hapi-swagger': { order: 1 } },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: faqRequest,
            },
            response: {
                status: {
                    201: faqResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'GET',
        path: '/faq/{id}',
        handler: faqHandler.getById,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('GET_FAQ_BY_ID_DESCRIPTION'),
            notes: I18N.t('GET_FAQ_BY_ID_NOTE'),
            plugins: { 'hapi-swagger': { order: 2 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageFaqs'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: faqIdentifier
            },
            response: {
                status: {
                    200: faqResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'GET',
        path: '/faq/{code}/byCode',
        handler: faqHandler.getByCode,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('GET_FAQ_BY_CODE_DESCRIPTION'),
            notes: I18N.t('GET_FAQ_BY_CODE_NOTE'),
            plugins: { 'hapi-swagger': { order: 3 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageFaqs'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: faqStringIdentifier
            },
            response: {
                status: {
                    200: faqResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'PATCH',
        path: '/faq/{id}',
        handler: faqHandler.update,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('UPDATE_FAQ_DESCRIPTION'),
            notes: I18N.t('UPDATE_FAQ_NOTE'),
            plugins: { 'hapi-swagger': { order: 4 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageFaqs'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: faqRequest,
                params: faqIdentifier
            },
            response: {
                status: {
                    200: faqResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'DELETE',
        path: '/faq/{id}',
        handler: faqHandler.delete,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('DELETE_FAQ_DESCRIPTION'),
            notes: I18N.t('DELETE_FAQ_NOTE'),
            plugins: { 'hapi-swagger': { order: 5 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageFaqs'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: faqIdentifier
            },
            response: {
                status: {
                    200: faqResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'GET',
        path: '/faq/list',
        handler: faqHandler.list,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('LIST_FAQ_DESCRIPTION'),
            notes: I18N.t('LIST_FAQ_NOTE'),
            plugins: { 'hapi-swagger': { order: 6 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageFaqs'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                query: faqListRequest
            },
            response: {
                status: {
                    200: faqListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'GET',
        path: '/faq/listAll',
        handler: faqHandler.listAll,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('LIST_ALL_FAQ_DESCRIPTION'),
            notes: I18N.t('LIST_ALL_FAQ_NOTE'),
            plugins: { 'hapi-swagger': { order: 7 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageFaqs'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                query: faqListAllRequest
            },
            response: {
                status: {
                    200: faqListAllResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'GET',
        path: '/faq/{id}/listRevisions',
        handler: faqHandler.listRevisions,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('LIST_FAQ_REVISIONS_DESCRIPTION'),
            notes: I18N.t('LIST_FAQ_REVISIONS_NOTE'),
            plugins: { 'hapi-swagger': { order: 8 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageFaqs'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: faqIdentifier,
                query: faqListRequest
            },
            response: {
                status: {
                    200: faqListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'POST',
        path: '/faq/{id}/restoreRevision',
        handler: faqHandler.restoreRevision,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('RESTORE_FAQ_REVISION'),
            notes: I18N.t('RESTORE_FAQ_REVISION_NOTE'),
            plugins: { 'hapi-swagger': { order: 9 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageFaqs'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: faqIdentifier
            },
            response: {
                status: {
                    200: faqResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'PATCH',
        path: '/faq/{id}/sortOrder',
        handler: faqHandler.setSortOrder,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('FAQ_SORT_ORDER_DESCRIPTION'),
            notes: I18N.t('FAQ_SORT_ORDER_NOTE'),
            plugins: { 'hapi-swagger': { order: 10 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: faqIdentifier,
                payload: faqSortOrderRequest
            },
            response: {
                status: {
                    200: confirmationOnly,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'PATCH',
        path: '/faq/{id}/status',
        handler: faqHandler.updateStatus,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('FAQ_STATUS_UPDATE_DESCRIPTION'),
            notes: I18N.t('FAQ_STATUS_UPDATE_NOTE'),
            plugins: { 'hapi-swagger': { order: 11 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: faqIdentifier,
                payload: faqStatusRequest
            },
            response: {
                status: {
                    200: faqResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    },
    {
        method: 'GET',
        path: '/faqs',
        handler: faqHandler.publicList,
        options: {
            tags: ['api', 'Faq'],
            description: I18N.t('LIST_FAQ_DESCRIPTION'),
            notes: I18N.t('LIST_FAQ_NOTE'),
            plugins: { 'hapi-swagger': { order: 12 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'user', 'manageFaqs'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                query: faqPublicListRequest
            },
            response: {
                status: {
                    200: faqListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        },
    }
]
export default routes