"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.optionalDate = exports.dateTransformSchema = exports.changePasswordSchema = exports.defaultPaginationSchema = exports.resetPasswordSchema = exports.resetOtpSchema = exports.verifyOtpSchema = exports.resendOtpSchema = exports.nullableDefaultTransformSchema = exports.defaultTransformSchema = exports.personSchema = exports.imageSchema = void 0;
const zod_1 = __importDefault(require("zod"));
const shared_1 = require("../../constant/shared");
exports.imageSchema = zod_1.default
    .any()
    .transform((val) => {
    if (!val || !val?.file_name || val?.file_name?.includes('uploads/common'))
        return null;
    const isHostIncluded = val?.file_name?.includes(process.env.SERVER_HOST);
    return {
        ...val,
        file_name: isHostIncluded
            ? val?.file_name
            : `${process.env.SERVER_HOST}/${val?.file_name}`,
    };
})
    .optional();
exports.personSchema = zod_1.default
    .object({
    id: zod_1.default.string(),
    name: zod_1.default.string().nullable().optional(),
    username: zod_1.default.string().nullable().optional(),
    image: exports.imageSchema,
})
    .nullable()
    .optional();
exports.defaultTransformSchema = zod_1.default
    .string()
    .transform((val) => {
    if (!val || val === shared_1.DEFAULT_VALUES.STRING)
        return '';
    return val;
})
    .optional();
exports.nullableDefaultTransformSchema = zod_1.default.preprocess((value) => (value === null || value === undefined ? '' : value), zod_1.default.string().transform((val) => {
    if (!val || val === shared_1.DEFAULT_VALUES.STRING)
        return '';
    return val;
}));
exports.resendOtpSchema = zod_1.default.object({
    email: zod_1.default.email('Invalid email address'),
});
exports.verifyOtpSchema = zod_1.default.object({
    email: zod_1.default.email('Invalid email address'),
    otp: zod_1.default.string('OTP is required'),
});
exports.resetOtpSchema = zod_1.default.object({
    email: zod_1.default.email('Invalid email address'),
    otp: zod_1.default.string('OTP is required'),
});
exports.resetPasswordSchema = zod_1.default.object({
    email: zod_1.default.email('Invalid email address'),
    password: zod_1.default
        .string()
        .min(6, { message: 'Password must be at least 6 characters long' })
        .regex(/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{6,}$/, {
        message: 'Password must contain at least one letter and one number',
    }),
});
exports.defaultPaginationSchema = zod_1.default.object({
    search: zod_1.default.string().trim().optional(),
    department: zod_1.default.string().trim().optional(),
    page: zod_1.default.preprocess((value) => {
        if (value === undefined || value === null || value === '')
            return 1;
        const parsed = Number(value);
        return Number.isNaN(parsed) ? value : parsed;
    }, zod_1.default.number().int().min(1).default(1)),
    limit: zod_1.default.preprocess((value) => {
        if (value === undefined || value === null || value === '')
            return 10;
        const parsed = Number(value);
        return Number.isNaN(parsed) ? value : parsed;
    }, zod_1.default.number().int().min(1).max(100).default(10)),
});
exports.changePasswordSchema = zod_1.default.object({
    current_password: zod_1.default.string({ message: 'Current password is required' }),
    new_password: zod_1.default
        .string()
        .min(6, { message: 'New password must be at least 6 characters long' })
        .regex(/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{6,}$/, {
        message: 'New password must contain at least one letter and one number',
    }),
});
exports.dateTransformSchema = zod_1.default
    .any()
    .transform((val) => {
    if (val === null || val === undefined)
        return null;
    const date = val instanceof Date ? val : new Date(val);
    return isNaN(date.getTime()) ? null : date.toISOString();
})
    .optional()
    .nullable();
exports.optionalDate = zod_1.default.preprocess((value) => {
    if (value === null || value === undefined || value === '')
        return undefined;
    return value;
}, zod_1.default.coerce.date().optional());
//# sourceMappingURL=shared.dto.js.map