import { ServerRoute } from '@hapi/hapi'
import Joi from '@hapi/joi'
import { NotificationHandler } from '../handlers/notification.handler'
import { options } from "../validators/global.validator.schema"
import { Common } from "../../utils/common"
import {
    notificationResponse,
    notificationRequest,
    notificationIdentifier,
    notificationStringIdentifier,
    notificationListRequest,
    notificationListResponse,
    notificationListAllRequest,
    notificationListAllResponse,
    notificationSortOrderRequest,
    notificationStatusRequest,
    testNotificationRequest
} from "../validators/notification.validator"
const notificationHandler = new NotificationHandler();
import { I18N } from '../../utils/i18n';
import { error400, error401, error403, error404, error500, confirmationOnly } from "../validators/global.validator.schema"
const routes: ServerRoute[] = [
    {
        method: 'POST',
        path: '/notification',
        handler: notificationHandler.create,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('CREATE_NOTIFICATION_DESCRIPTION'),
            notes: I18N.t('CREATE_NOTIFICATION_NOTE'),
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            plugins: { 'hapi-swagger': { order: 1 } },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: notificationRequest,
            },
            response: {
                status: {
                    201: notificationResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/notification/{id}',
        handler: notificationHandler.getById,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('GET_NOTIFICATION_BY_ID_DESCRIPTION'),
            notes: I18N.t('GET_NOTIFICATION_BY_ID_NOTE'),
            plugins: { 'hapi-swagger': { order: 2 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: notificationIdentifier
            },
            response: {
                status: {
                    200: notificationResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/notification/{code}/byCode',
        handler: notificationHandler.getByCode,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('GET_NOTIFICATION_BY_CODE_DESCRIPTION'),
            notes: I18N.t('GET_NOTIFICATION_BY_CODE_NOTE'),
            plugins: { 'hapi-swagger': { order: 3 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: notificationStringIdentifier
            },
            response: {
                status: {
                    200: notificationResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'PATCH',
        path: '/notification/{id}',
        handler: notificationHandler.update,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('UPDATE_NOTIFICATION_DESCRIPTION'),
            notes: I18N.t('UPDATE_NOTIFICATION_NOTE'),
            plugins: { 'hapi-swagger': { order: 4 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: notificationRequest,
                params: notificationIdentifier
            },
            response: {
                status: {
                    200: notificationResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'DELETE',
        path: '/notification/{id}',
        handler: notificationHandler.delete,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('DELETE_NOTIFICATION_DESCRIPTION'),
            notes: I18N.t('DELETE_NOTIFICATION_NOTE'),
            plugins: { 'hapi-swagger': { order: 5 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: notificationIdentifier
            },
            response: {
                status: {
                    200: notificationResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/notification/list',
        handler: notificationHandler.list,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('LIST_NOTIFICATION_DESCRIPTION'),
            notes: I18N.t('LIST_NOTIFICATION_NOTE'),
            plugins: { 'hapi-swagger': { order: 6 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                query: notificationListRequest
            },
            response: {
                status: {
                    200: notificationListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/notification/listAll',
        handler: notificationHandler.listAll,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('LIST_ALL_NOTIFICATION_DESCRIPTION'),
            notes: I18N.t('LIST_ALL_NOTIFICATION_NOTE'),
            plugins: { 'hapi-swagger': { order: 7 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                query: notificationListAllRequest
            },
            response: {
                status: {
                    200: notificationListAllResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/notification/{id}/listRevisions',
        handler: notificationHandler.listRevisions,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('LIST_NOTIFICATION_REVISIONS_DESCRIPTION'),
            notes: I18N.t('LIST_NOTIFICATION_REVISIONS_NOTE'),
            plugins: { 'hapi-swagger': { order: 8 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: notificationIdentifier,
                query: notificationListRequest
            },
            response: {
                status: {
                    200: notificationListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'POST',
        path: '/notification/{id}/restoreRevision',
        handler: notificationHandler.restoreRevision,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('RESTORE_NOTIFICATION_REVISION'),
            notes: I18N.t('RESTORE_NOTIFICATION_REVISION_NOTE'),
            plugins: { 'hapi-swagger': { order: 9 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: notificationIdentifier
            },
            response: {
                status: {
                    200: notificationResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'POST',
        path: '/notification/testNotification',
        handler: notificationHandler.sendTestNotification,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('TEST_NOTIFICATION_DESCRIPTION'),
            notes: I18N.t('TEST_NOTIFICATION_NOTE'),
            plugins: { 'hapi-swagger': { order: 9 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: testNotificationRequest
            },
            response: {
                status: {
                    200: confirmationOnly,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'PATCH',
        path: '/notification/{id}/sortOrder',
        handler: notificationHandler.setSortOrder,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('NOTIFICATION_SORT_ORDER_DESCRIPTION'),
            notes: I18N.t('NOTIFICATION_SORT_ORDER_NOTE'),
            plugins: { 'hapi-swagger': { order: 10 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: notificationIdentifier,
                payload: notificationSortOrderRequest
            },
            response: {
                status: {
                    200: confirmationOnly,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'PATCH',
        path: '/notification/{id}/status',
        handler: notificationHandler.updateStatus,
        options: {
            tags: ['api', 'Notifications'],
            description: I18N.t('NOTIFICATION_STATUS_UPDATE_DESCRIPTION'),
            notes: I18N.t('NOTIFICATION_STATUS_UPDATE_NOTE'),
            plugins: { 'hapi-swagger': { order: 11 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageNotifications'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: notificationIdentifier,
                payload: notificationStatusRequest
            },
            response: {
                status: {
                    200: notificationResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    }
]
export default routes