import { ServerRoute } from '@hapi/hapi';
import { NotificationLogHandler } from '../handlers/notificationLog.handler';
import { options } from "../validators/global.validator.schema";
import { Common } from "../../utils/common";
import { I18N } from '../../utils/i18n';
import {
    notificationLogIdentifier,
    notificationLogListRequest,
    notificationLogResponse,
    notificationLogListResponse,
    notificationLogUnreadCountResponse,
    error400, error401, error403, error404, error500
} from "../validators/notificationLog.validator";

const notificationLogHandler = new NotificationLogHandler();

const routes: ServerRoute[] = [
    {
        method: 'GET',
        path: '/notificationLog/list',
        handler: notificationLogHandler.list,
        options: {
            tags: ['api', 'Notification Logs'],
            description: I18N.t('LIST_NOTIFICATION_LOGS_DESCRIPTION'),
            auth: { strategies: ['jwt'] },
            plugins: { 'hapi-swagger': { order: 1 } },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                query: notificationLogListRequest
            },
            response: {
                status: {
                    200: notificationLogListResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    500: error500
                }
            }
        }
    },
    {
        method: 'GET',
        path: '/notificationLog/unread-count',
        handler: notificationLogHandler.unreadCount,
        options: {
            tags: ['api', 'Notification Logs'],
            description: I18N.t('GET_NOTIFICATION_LOG_UNREAD_COUNT_DESCRIPTION'),
            auth: { strategies: ['jwt'] },
            plugins: { 'hapi-swagger': { order: 2 } },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover
            },
            response: {
                status: {
                    200: notificationLogUnreadCountResponse,
                    401: error401,
                    500: error500
                }
            }
        }
    },
    {
        method: 'PATCH',
        path: '/notificationLog/{id}/view',
        handler: notificationLogHandler.markViewed,
        options: {
            tags: ['api', 'Notification Logs'],
            description: I18N.t('MARK_NOTIFICATION_LOG_VIEWED_DESCRIPTION'),
            auth: { strategies: ['jwt'] },
            plugins: { 'hapi-swagger': { order: 2 } },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: notificationLogIdentifier
            },
            response: {
                status: {
                    200: notificationLogResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        }
    },
    {
        method: 'PATCH',
        path: '/notificationLog/{id}/read',
        handler: notificationLogHandler.markRead,
        options: {
            tags: ['api', 'Notification Logs'],
            description: I18N.t('MARK_NOTIFICATION_LOG_READ_DESCRIPTION'),
            auth: { strategies: ['jwt'] },
            plugins: { 'hapi-swagger': { order: 3 } },
            validate: {
                headers: Common.routeHeaders("authorized"),
                options: options,
                failAction: Common.failover,
                params: notificationLogIdentifier
            },
            response: {
                status: {
                    200: notificationLogResponse,
                    400: error400,
                    401: error401,
                    403: error403,
                    404: error404,
                    500: error500
                }
            }
        }
    }
];

export default routes;
