import { ServerRoute } from '@hapi/hapi'
import Joi from '@hapi/joi'
import { EmailTemplateHandler } from '../handlers/emailTemplate.handler'
import { options } from "../validators/global.validator.schema"
import { Common } from "../../utils/common"
import {
    emailTemplateResponse,
    emailTemplateRequest,
    emailTemplateIdentifier,
    emailTemplateStringIdentifier,
    emailTemplateListRequest,
    emailTemplateListResponse,
    emailTemplateListAllRequest,
    emailTemplateListAllResponse,
    emailTemplateSortOrderRequest,
    emailTemplateStatusRequest,
    testEmailRequest
} from "../validators/emailTemplate.validator"
const emailTemplateHandler = new EmailTemplateHandler();
import { I18N } from '../../utils/i18n';
import { error400, error401, error403, error404, error500, confirmationOnly } from "../validators/global.validator.schema"
const routes: ServerRoute[] = [
    {
        method: 'POST',
        path: '/emailTemplate',
        handler: emailTemplateHandler.create,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('CREATE_EMAIL_TEMPLATE_DESCRIPTION'),
            notes: I18N.t('CREATE_EMAIL_TEMPLATE_NOTE'),
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            plugins: { 'hapi-swagger': { order: 1 } },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: emailTemplateRequest,
            },
            response: {
                status: {
                    201: emailTemplateResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/emailTemplate/{id}',
        handler: emailTemplateHandler.getById,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('GET_EMAIL_TEMPLATE_BY_ID_DESCRIPTION'),
            notes: I18N.t('GET_EMAIL_TEMPLATE_BY_ID_NOTE'),
            plugins: { 'hapi-swagger': { order: 2 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: emailTemplateIdentifier
            },
            response: {
                status: {
                    200: emailTemplateResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/emailTemplate/{code}/byCode',
        handler: emailTemplateHandler.getByCode,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('GET_EMAIL_TEMPLATE_BY_CODE_DESCRIPTION'),
            notes: I18N.t('GET_EMAIL_TEMPLATE_BY_CODE_NOTE'),
            plugins: { 'hapi-swagger': { order: 3 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: emailTemplateStringIdentifier
            },
            response: {
                status: {
                    200: emailTemplateResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'PATCH',
        path: '/emailTemplate/{id}',
        handler: emailTemplateHandler.update,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('UPDATE_EMAIL_TEMPLATE_DESCRIPTION'),
            notes: I18N.t('UPDATE_EMAIL_TEMPLATE_NOTE'),
            plugins: { 'hapi-swagger': { order: 4 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: emailTemplateRequest,
                params: emailTemplateIdentifier
            },
            response: {
                status: {
                    200: emailTemplateResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'DELETE',
        path: '/emailTemplate/{id}',
        handler: emailTemplateHandler.delete,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('DELETE_EMAIL_TEMPLATE_DESCRIPTION'),
            notes: I18N.t('DELETE_EMAIL_TEMPLATE_NOTE'),
            plugins: { 'hapi-swagger': { order: 5 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: emailTemplateIdentifier
            },
            response: {
                status: {
                    200: emailTemplateResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/emailTemplate/list',
        handler: emailTemplateHandler.list,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('LIST_EMAIL_TEMPLATE_DESCRIPTION'),
            notes: I18N.t('LIST_EMAIL_TEMPLATE_NOTE'),
            plugins: { 'hapi-swagger': { order: 6 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                query: emailTemplateListRequest
            },
            response: {
                status: {
                    200: emailTemplateListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/emailTemplate/listAll',
        handler: emailTemplateHandler.listAll,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('LIST_ALL_EMAIL_TEMPLATE_DESCRIPTION'),
            notes: I18N.t('LIST_ALL_EMAIL_TEMPLATE_NOTE'),
            plugins: { 'hapi-swagger': { order: 7 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                query: emailTemplateListAllRequest
            },
            response: {
                status: {
                    200: emailTemplateListAllResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/emailTemplate/{id}/listRevisions',
        handler: emailTemplateHandler.listRevisions,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('LIST_EMAIL_TEMPLATE_REVISIONS_DESCRIPTION'),
            notes: I18N.t('LIST_EMAIL_TEMPLATE_REVISIONS_NOTE'),
            plugins: { 'hapi-swagger': { order: 8 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: emailTemplateIdentifier,
                query: emailTemplateListRequest
            },
            response: {
                status: {
                    200: emailTemplateListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'POST',
        path: '/emailTemplate/{id}/restoreRevision',
        handler: emailTemplateHandler.restoreRevision,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('RESTORE_EMAIL_TEMPLATE_REVISION'),
            notes: I18N.t('RESTORE_EMAIL_TEMPLATE_REVISION_NOTE'),
            plugins: { 'hapi-swagger': { order: 9 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: emailTemplateIdentifier
            },
            response: {
                status: {
                    200: emailTemplateResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'POST',
        path: '/emailTemplate/testEmail',
        handler: emailTemplateHandler.sendTestMail,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('TEST_EMAIL_DESCRIPTION'),
            notes: I18N.t('TEST_EMAIL_NOTE'),
            plugins: { 'hapi-swagger': { order: 9 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: testEmailRequest
            },
            response: {
                status: {
                    200: confirmationOnly,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'PATCH',
        path: '/emailTemplate/{id}/sortOrder',
        handler: emailTemplateHandler.setSortOrder,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('EMAIL_TEMPLATE_SORT_ORDER_DESCRIPTION'),
            notes: I18N.t('EMAIL_TEMPLATE_SORT_ORDER_NOTE'),
            plugins: { 'hapi-swagger': { order: 10 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: emailTemplateIdentifier,
                payload: emailTemplateSortOrderRequest
            },
            response: {
                status: {
                    200: confirmationOnly,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'PATCH',
        path: '/emailTemplate/{id}/status',
        handler: emailTemplateHandler.updateStatus,
        options: {
            tags: ['api', 'Email Templates'],
            description: I18N.t('EMAIL_TEMPLATE_STATUS_UPDATE_DESCRIPTION'),
            notes: I18N.t('EMAIL_TEMPLATE_STATUS_UPDATE_NOTE'),
            plugins: { 'hapi-swagger': { order: 11 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageEmailTemplates'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: emailTemplateIdentifier,
                payload: emailTemplateStatusRequest
            },
            response: {
                status: {
                    200: emailTemplateResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    }
]
export default routes