import { ServerRoute } from '@hapi/hapi'
import { CategoryHandler } from '../handlers/category.handler'
import { options } from "../validators/global.validator.schema"
import { Common } from "../../utils/common"
import {
    categoryResponse,
    categoryRequest,
    categoryIdentifier,
    categoryStringIdentifier,
    categoryListRequest,
    categoryListRevisionRequest,
    categoryListResponse,
    categoryListAllRequest,
    categoryListAllResponse,
    categoryTypeIdentifier,
    categoryTreeResponse,
    categorySortOrderRequest,
    categoryTypeCodeIdentifier,
    categoryStatusRequest,
    categorySortIdentityIdentifier,
    tagListAllRequest,
    categoriesListRequest,
    categoryListAllActiveRequest
} from "../validators/category.validator"
const categoryHandler = new CategoryHandler();
import { I18N } from '../../utils/i18n';
import { error400, error401, error403, error404, error500, confirmationOnly } from "../validators/global.validator.schema"
const routes: ServerRoute[] = [
    {
        method: 'POST',
        path: '/category',
        handler: categoryHandler.create,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('CREATE_CATEGORY_DESCRIPTION'),
            notes: I18N.t('CREATE_CATEGORY_NOTE'),
            plugins: { 'hapi-swagger': { order: 1 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: categoryRequest,
            },
            response: {
                status: {
                    200: categoryResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/category/{id}',
        handler: categoryHandler.getById,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('GET_CATEGORY_BY_ID_DESCRIPTION'),
            notes: I18N.t('GET_CATEGORY_BY_ID_NOTE'),
            plugins: { 'hapi-swagger': { order: 2 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: categoryIdentifier
            },
            response: {
                status: {
                    200: categoryResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/category/{code}/byCode',
        handler: categoryHandler.getByCode,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('GET_CATEGORY_BY_CODE_DESCRIPTION'),
            notes: I18N.t('GET_CATEGORY_BY_CODE_NOTE'),
            plugins: { 'hapi-swagger': { order: 3 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: categoryStringIdentifier
            },
            response: {
                status: {
                    200: categoryResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'PATCH',
        path: '/category/{id}',
        handler: categoryHandler.update,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('UPDATE_CATEGORY_DESCRIPTION'),
            notes: I18N.t('UPDATE_CATEGORY_NOTE'),
            plugins: { 'hapi-swagger': { order: 4 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                payload: categoryRequest,
                params: categoryIdentifier
            },
            response: {
                status: {
                    200: categoryResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'DELETE',
        path: '/category/{categoryTypeCode}/{id}',
        handler: categoryHandler.delete,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('DELETE_CATEGORY_DESCRIPTION'),
            notes: I18N.t('DELETE_CATEGORY_NOTE'),
            plugins: { 'hapi-swagger': { order: 5 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: categorySortIdentityIdentifier,
            },
            response: {
                status: {
                    200: categoryResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/category/{categoryTypeCode}/list',
        handler: categoryHandler.list,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('LIST_CATEGORY_DESCRIPTION'),
            notes: I18N.t('LIST_CATEGORY_NOTE'),
            plugins: { 'hapi-swagger': { order: 6 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: categoryTypeCodeIdentifier,
                query: categoryListRequest
            },
            response: {
                status: {
                    200: categoryListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/category/{categoryTypeCode}/categories',
        handler: categoryHandler.categories,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('LIST_CATEGORY_DESCRIPTION'),
            notes: I18N.t('LIST_CATEGORY_NOTE'),
            plugins: { 'hapi-swagger': { order: 6 } },
            auth: { strategies: ['jwt'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: categoryTypeCodeIdentifier,
                query: categoriesListRequest
            },
            response: {
                status: {
                    200: categoryListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/category/{categoryTypeCode}/listAll',
        handler: categoryHandler.listAll,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('LIST_ALL_CATEGORY_DESCRIPTION'),
            notes: I18N.t('LIST_ALL_CATEGORY_NOTE'),
            plugins: { 'hapi-swagger': { order: 7 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategoryTypes', 'user'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: categoryTypeCodeIdentifier,
                query: categoryListAllRequest
            },
            response: {
                status: {
                    200: categoryListAllResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/category/{categoryTypeCode}/all',
        handler: categoryHandler.listAllActive,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('LIST_ALL_CATEGORY_DESCRIPTION'),
            notes: I18N.t('LIST_ALL_CATEGORY_NOTE'),
            plugins: { 'hapi-swagger': { order: 7 } },
            auth: { strategies: ['jwt'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: categoryTypeCodeIdentifier,
                query: categoryListAllActiveRequest
            },
            response: {
                status: {
                    200: categoryListAllResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/category/public/{categoryTypeCode}/listAll',
        handler: categoryHandler.listAllActive,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('LIST_ALL_CATEGORY_DESCRIPTION'),
            notes: I18N.t('LIST_ALL_CATEGORY_NOTE'),
            plugins: { 'hapi-swagger': { order: 7 } },
            auth: false,
            validate: {
                headers: Common.routeHeaders(),
                options: options,
                failAction: Common.failover,
                params: categoryTypeCodeIdentifier,
                query: categoryListAllActiveRequest
            },
            response: {
                status: {
                    200: categoryListAllResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/category/public/{categoryTypeCode}/tree',
        handler: categoryHandler.getCategoryTree,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('LIST_CATEGORY_REVISIONS_DESCRIPTION'),
            notes: I18N.t('LIST_CATEGORY_REVISIONS_NOTE'),
            plugins: { 'hapi-swagger': { order: 9 } },
            auth: false,
            validate: {
                headers: Common.routeHeaders(),
                options: options,
                failAction: Common.failover,
                params: categoryTypeCodeIdentifier
            },
            response: {
                status: {
                    200: categoryTreeResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/tags',
        handler: categoryHandler.listAllTags,
        options: {
            tags: ['api', 'Tag'],
            description: I18N.t('LIST_ALL_TAG_DESCRIPTION'),
            notes: I18N.t('LIST_ALL_TAG_NOTE'),
            plugins: { 'hapi-swagger': { order: 7 } },
            auth: false,
            validate: {
                headers: Common.routeHeaders(),
                options: options,
                failAction: Common.failover,
                query: tagListAllRequest
            },
            response: {
                status: {
                    200: categoryListAllResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/category/{id}/listRevisions',
        handler: categoryHandler.listRevisions,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('LIST_CATEGORY_REVISIONS_DESCRIPTION'),
            notes: I18N.t('LIST_CATEGORY_REVISIONS_NOTE'),
            plugins: { 'hapi-swagger': { order: 8 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: categoryIdentifier,
                query: categoryListRevisionRequest
            },
            response: {
                status: {
                    200: categoryListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'POST',
        path: '/category/{id}/restoreRevision',
        handler: categoryHandler.restoreRevision,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('LIST_CATEGORY_REVISIONS_DESCRIPTION'),
            notes: I18N.t('LIST_CATEGORY_REVISIONS_NOTE'),
            plugins: { 'hapi-swagger': { order: 9 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: categoryIdentifier
            },
            response: {
                status: {
                    200: categoryResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'GET',
        path: '/category/{categoryTypeCode}/tree',
        handler: categoryHandler.getCategoryTree,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('LIST_CATEGORY_REVISIONS_DESCRIPTION'),
            notes: I18N.t('LIST_CATEGORY_REVISIONS_NOTE'),
            plugins: { 'hapi-swagger': { order: 9 } },
            auth: { strategies: ['jwt'], scope: ['admin', 'manageCategories'] },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: categoryTypeCodeIdentifier
            },
            response: {
                status: {
                    200: categoryTreeResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'PATCH',
        path: '/category/{categoryTypeCode}/{id}/sortOrder',
        handler: categoryHandler.setSortOrder,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('CATEGORY_SORT_ORDER_DESCRIPTION'),
            notes: I18N.t('CATEGORY_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: categorySortIdentityIdentifier,
                payload: categorySortOrderRequest
            },
            response: {
                status: {
                    200: confirmationOnly,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    },
    {
        method: 'PATCH',
        path: '/category/{id}/status',
        handler: categoryHandler.updateStatus,
        options: {
            tags: ['api', 'Category'],
            description: I18N.t('CATEGORY_STATUS_UPDATE_DESCRIPTION'),
            notes: I18N.t('CATEGORY_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: categoryIdentifier,
                payload: categoryStatusRequest
            },
            response: {
                status: {
                    200: categoryResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }

            }
        },
    }
]

export default routes
