import { RequestHandler } from 'express';
import { HumandResponse } from '../types/response';
import { TimestampCursorPaginationVC } from '../validationClasses/timestampCursorPaginationVC';
import { genericValidateParams } from './genericValidateParams';

export const validateTimestampCursorPagination: RequestHandler<any, HumandResponse, any, any, any> = genericValidateParams(
    (req) => req.query as unknown as TimestampCursorPaginationVC,
    (res, output: TimestampCursorPaginationVC) => {
        res.locals.timestampCursorPagination = {
            cursor: output.cursor || null,
            limit: output.limit || undefined,
            timestamp: output.timestamp ? new Date(output.timestamp) : undefined,
        };
    },
    TimestampCursorPaginationVC,
);
