"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.memberOptionsResponseSchema = exports.memberOptionSchema = exports.memberListResponsesSchema = exports.memberListResponseSchema = exports.membersResponseSchema = exports.memberResponseSchema = exports.memberPreviewSchema = exports.updateMemberSchema = exports.createMemberSchema = exports.educationResponseSchema = exports.createEducationSchema = exports.workExperienceResponseSchema = exports.createWorkExperienceSchema = exports.filterMembersSchema = exports.signinMemberSchema = void 0;
const zod_1 = require("zod");
const shared_dto_1 = require("../shared/shared.dto");
const optionalString = zod_1.z.preprocess((value) => {
    if (typeof value === 'string' && value.trim() === '')
        return undefined;
    return value;
}, zod_1.z.string().trim().optional());
const optionalUuid = zod_1.z.preprocess((value) => {
    if (typeof value === 'string' && value.trim() === '')
        return undefined;
    return value;
}, zod_1.z.string().uuid().optional());
const optionalDate = zod_1.z.preprocess((value) => {
    if (value === null || value === undefined || value === '')
        return undefined;
    return value;
}, zod_1.z.coerce.date().optional());
const requiredName = (label) => zod_1.z
    .string()
    .trim()
    .min(2, { message: `${label} must be at least 2 characters long` });
const passwordSchema = zod_1.z
    .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',
});
const genderSchema = zod_1.z.enum(['male', 'female', 'others']);
const memberStatusSchema = zod_1.z.enum([
    'active',
    'deactivated',
    'terminated',
    'deceased',
    'resigned',
    'deleted',
]);
const maritalStatusSchema = zod_1.z.enum([
    'single',
    'married',
    'divorced',
    'widowed',
]);
exports.signinMemberSchema = zod_1.z
    .object({
    email: zod_1.z.email({ message: 'Invalid email address' }).optional(),
    employee_id: zod_1.z.string().trim().optional(),
    password: zod_1.z.string({ message: 'Password is required' }),
    device_id: zod_1.z.string().trim().optional(),
    device_name: zod_1.z.string().trim().optional(),
})
    .refine((data) => data.employee_id || data.email, {
    message: 'Either username or email must be provided',
});
exports.filterMembersSchema = zod_1.z.object({
    status: memberStatusSchema.optional(),
    search: zod_1.z.string().trim().optional(),
    department: zod_1.z.string().trim().optional(),
    page: zod_1.z.preprocess((value) => {
        if (value === undefined || value === null || value === '')
            return 1;
        const parsed = Number(value);
        return Number.isNaN(parsed) ? value : parsed;
    }, zod_1.z.number().int().min(1).default(1)),
    limit: zod_1.z.preprocess((value) => {
        if (value === undefined || value === null || value === '')
            return 10;
        const parsed = Number(value);
        return Number.isNaN(parsed) ? value : parsed;
    }, zod_1.z.number().int().min(1).max(100).default(10)),
    attention: zod_1.z.preprocess((value) => {
        if (typeof value === 'boolean')
            return value;
        if (typeof value === 'string') {
            const normalized = value.trim().toLowerCase();
            if (normalized === 'true')
                return true;
            if (normalized === 'false')
                return false;
        }
        return undefined;
    }, zod_1.z.boolean().optional()),
    data_scope: zod_1.z.enum(['own', 'all']).optional(),
});
exports.createWorkExperienceSchema = zod_1.z.object({
    company: zod_1.z.string().trim().min(1, { message: 'Company name is required' }),
    position: zod_1.z.string().trim().min(1, { message: 'Position is required' }),
    start_date: zod_1.z.coerce.date({ message: 'Start date is required' }),
    end_date: optionalDate,
    description: optionalString,
    relevant: zod_1.z.boolean().optional().default(false),
});
exports.workExperienceResponseSchema = zod_1.z.object({
    id: zod_1.z.string().uuid().optional(),
    company: zod_1.z.string().optional(),
    position: zod_1.z.string().optional(),
    start_date: zod_1.z
        .date()
        .transform((date) => date.toISOString())
        .optional(),
    end_date: zod_1.z
        .date()
        .transform((date) => date.toISOString())
        .optional()
        .nullable(),
    description: shared_dto_1.defaultTransformSchema,
    relevant: zod_1.z.boolean().optional(),
    created_at: shared_dto_1.dateTransformSchema,
    updated_at: shared_dto_1.dateTransformSchema,
});
exports.createEducationSchema = zod_1.z.object({
    institution: zod_1.z.string().trim().min(1, { message: 'Institution is required' }),
    degree: zod_1.z.string().trim().min(1, { message: 'Degree is required' }),
    field: zod_1.z.string().trim().min(1, { message: 'Field is required' }),
    start_date: zod_1.z.coerce.date({ message: 'Start date is required' }),
    end_date: optionalDate,
    description: optionalString,
    relevant: zod_1.z.boolean().optional().default(false),
});
exports.educationResponseSchema = zod_1.z.object({
    id: zod_1.z.string().uuid().optional(),
    institution: zod_1.z.string().optional(),
    degree: zod_1.z.string().optional(),
    field: zod_1.z.string().optional(),
    start_date: zod_1.z
        .date()
        .transform((date) => date.toISOString())
        .optional(),
    end_date: zod_1.z
        .date()
        .transform((date) => date.toISOString())
        .optional()
        .nullable(),
    description: shared_dto_1.defaultTransformSchema,
    relevant: zod_1.z.boolean().optional(),
    created_at: shared_dto_1.dateTransformSchema,
    updated_at: shared_dto_1.dateTransformSchema,
});
const memberBaseSchema = zod_1.z.object({
    email: zod_1.z.email({ message: 'Invalid email address' }),
    work_email: optionalString,
    image: shared_dto_1.imageSchema.optional(),
    role: zod_1.z.enum(['owner', 'admin', 'member']).optional(),
    access_role_id: optionalUuid,
    employee_id: zod_1.z.string().trim().min(1, { message: 'Employee ID is required' }),
    nickname: optionalString,
    first_name: requiredName('First name'),
    last_name: optionalString,
    password: passwordSchema,
    about: optionalString,
    expertise: optionalString,
    work_phone: optionalString,
    phone: optionalString,
    present_address_line_one: optionalString,
    present_address_line_two: optionalString,
    present_address_city: optionalString,
    present_address_country: optionalString,
    present_address_state: optionalString,
    present_address_zip_code: optionalString,
    permanent_address_line_one: optionalString,
    permanent_address_line_two: optionalString,
    permanent_address_city: optionalString,
    permanent_address_country: optionalString,
    permanent_address_state: optionalString,
    permanent_address_zip_code: optionalString,
    father_name: optionalString,
    mother_name: optionalString,
    emargency_contact_name: optionalString,
    emargency_contact_phone: optionalString,
    emargency_contact_relation: optionalString,
    gender: genderSchema,
    date_of_birth: optionalDate,
    date_of_joining: zod_1.z.date().transform((date) => date.toISOString()),
    department_id: optionalUuid,
    designation_id: optionalUuid,
    location_id: optionalUuid,
    employment_type_id: optionalUuid,
    hiring_source_id: optionalUuid,
    reporting_manager_id: optionalUuid,
    status: memberStatusSchema,
    marital_status: maritalStatusSchema,
});
exports.createMemberSchema = memberBaseSchema.extend({
    access_role_id: zod_1.z.string().uuid({ message: 'Access role is required' }),
    work_email: optionalString,
    nickname: optionalString,
    last_name: optionalString,
    about: optionalString,
    expertise: optionalString,
    work_phone: optionalString,
    phone: optionalString,
    present_address_line_one: optionalString,
    present_address_line_two: optionalString,
    present_address_city: optionalString,
    present_address_country: optionalString,
    present_address_state: optionalString,
    present_address_zip_code: optionalString,
    permanent_address_line_one: optionalString,
    permanent_address_line_two: optionalString,
    permanent_address_city: optionalString,
    permanent_address_country: optionalString,
    permanent_address_state: optionalString,
    permanent_address_zip_code: optionalString,
    father_name: optionalString,
    mother_name: optionalString,
    emergency_contact_name: optionalString,
    emergency_contact_phone: optionalString,
    emergency_contact_relationship: optionalString,
    gender: genderSchema.optional(),
    marital_status: maritalStatusSchema.optional(),
    date_of_birth: optionalDate,
    date_of_joining: optionalDate,
    department_id: optionalUuid,
    designation_id: optionalUuid,
    location_id: optionalUuid,
    employment_type_id: optionalUuid,
    hiring_source_id: optionalUuid,
    reporting_manager_id: optionalUuid,
    status: memberStatusSchema.optional(),
    work_experiences: zod_1.z.array(exports.createWorkExperienceSchema).optional(),
    educations: zod_1.z.array(exports.createEducationSchema).optional(),
});
exports.updateMemberSchema = memberBaseSchema
    .partial()
    .extend({
    image: shared_dto_1.imageSchema.nullable().optional(),
    date_of_joining: optionalDate,
    department_id: optionalUuid,
    designation_id: optionalUuid,
    location_id: optionalUuid,
    employment_type_id: optionalUuid,
    hiring_source_id: optionalUuid,
    reporting_manager_id: optionalUuid,
    father_name: optionalString,
    mother_name: optionalString,
    emergency_contact_name: optionalString,
    emergency_contact_phone: optionalString,
    emergency_contact_relationship: optionalString,
    work_experiences: zod_1.z.array(exports.createWorkExperienceSchema).optional(),
    educations: zod_1.z.array(exports.createEducationSchema).optional(),
})
    .refine((data) => Object.keys(data).length > 0, {
    message: 'At least one field must be provided',
});
exports.memberPreviewSchema = zod_1.z.object({
    id: zod_1.z.string().uuid(),
    first_name: zod_1.z.string(),
    last_name: zod_1.z.string().optional().nullable(),
    email: zod_1.z.string().email().optional().nullable(),
    employee_id: zod_1.z.string(),
    department_id: zod_1.z.string().uuid().optional().nullable(),
    reporting_manager_id: zod_1.z.string().uuid().optional().nullable(),
    status: memberStatusSchema,
});
exports.memberResponseSchema = zod_1.z.object({
    id: zod_1.z.string().uuid().optional(),
    email: zod_1.z.string().email().optional(),
    work_email: shared_dto_1.defaultTransformSchema,
    employee_id: zod_1.z.string().optional(),
    nickname: shared_dto_1.defaultTransformSchema,
    first_name: zod_1.z.string().optional(),
    last_name: shared_dto_1.defaultTransformSchema,
    about: shared_dto_1.defaultTransformSchema,
    expertise: shared_dto_1.defaultTransformSchema,
    work_phone: shared_dto_1.defaultTransformSchema,
    phone: shared_dto_1.defaultTransformSchema,
    image: shared_dto_1.imageSchema.optional(),
    role: zod_1.z.enum(['owner', 'admin', 'member']).optional(),
    access_role_id: zod_1.z.string().uuid().optional().nullable(),
    present_address_line_one: shared_dto_1.defaultTransformSchema,
    present_address_line_two: shared_dto_1.defaultTransformSchema,
    present_address_city: shared_dto_1.defaultTransformSchema,
    present_address_country: shared_dto_1.defaultTransformSchema,
    present_address_state: shared_dto_1.defaultTransformSchema,
    present_address_zip_code: shared_dto_1.defaultTransformSchema,
    permanent_address_line_one: shared_dto_1.defaultTransformSchema,
    permanent_address_line_two: shared_dto_1.defaultTransformSchema,
    permanent_address_city: shared_dto_1.defaultTransformSchema,
    permanent_address_country: shared_dto_1.defaultTransformSchema,
    permanent_address_state: shared_dto_1.defaultTransformSchema,
    permanent_address_zip_code: shared_dto_1.defaultTransformSchema,
    father_name: shared_dto_1.defaultTransformSchema,
    mother_name: shared_dto_1.defaultTransformSchema,
    emergency_contact_name: shared_dto_1.defaultTransformSchema,
    emergency_contact_phone: shared_dto_1.defaultTransformSchema,
    emergency_contact_relationship: shared_dto_1.defaultTransformSchema,
    gender: genderSchema.optional(),
    marital_status: maritalStatusSchema.optional(),
    date_of_birth: zod_1.z
        .date()
        .transform((date) => date.toISOString())
        .optional()
        .nullable(),
    date_of_joining: optionalDate,
    department_id: zod_1.z.string().uuid().optional().nullable(),
    designation_id: zod_1.z.string().uuid().optional().nullable(),
    location_id: zod_1.z.string().uuid().optional().nullable(),
    employment_type_id: zod_1.z.string().uuid().optional().nullable(),
    hiring_source_id: zod_1.z.string().uuid().optional().nullable(),
    reporting_manager_id: zod_1.z.string().uuid().optional().nullable(),
    status: memberStatusSchema.optional(),
    department: zod_1.z
        .object({
        id: zod_1.z.string().uuid(),
        name: zod_1.z.string(),
    })
        .optional()
        .nullable(),
    designation: zod_1.z
        .object({
        id: zod_1.z.string().uuid(),
        name: zod_1.z.string(),
    })
        .optional()
        .nullable(),
    location: zod_1.z
        .object({
        id: zod_1.z.string().uuid(),
        name: zod_1.z.string(),
    })
        .optional()
        .nullable(),
    employment_type: zod_1.z
        .object({
        id: zod_1.z.string().uuid(),
        name: zod_1.z.string(),
    })
        .optional()
        .nullable(),
    hiring_source: zod_1.z
        .object({
        id: zod_1.z.string().uuid(),
        name: zod_1.z.string(),
    })
        .optional()
        .nullable(),
    work_experiences: zod_1.z.array(exports.workExperienceResponseSchema).optional(),
    educations: zod_1.z.array(exports.educationResponseSchema).optional(),
    created_at: shared_dto_1.dateTransformSchema,
    updated_at: shared_dto_1.dateTransformSchema,
    token: zod_1.z.string().optional(),
});
exports.membersResponseSchema = zod_1.z.array(exports.memberResponseSchema);
exports.memberListResponseSchema = exports.memberResponseSchema.extend({
    attendance_percentage: zod_1.z.number().optional(),
    total_leave: zod_1.z.number().optional(),
    leave_balance: zod_1.z.number().optional(),
    total_working_days: zod_1.z.number().optional(),
    total_working_hours: zod_1.z.number().optional(),
    assigned_leave: zod_1.z.number().optional(),
});
exports.memberListResponsesSchema = zod_1.z.array(exports.memberListResponseSchema);
exports.memberOptionSchema = zod_1.z.object({
    id: zod_1.z.string().uuid(),
    first_name: zod_1.z.string(),
    last_name: zod_1.z.string().optional().nullable(),
    email: zod_1.z.string().email().optional().nullable(),
    image: shared_dto_1.imageSchema.optional(),
    employee_id: zod_1.z.string(),
    department_id: zod_1.z.string().uuid().optional().nullable(),
    status: memberStatusSchema,
    role: zod_1.z.string().optional(),
    access_token: zod_1.z.string().optional(),
});
exports.memberOptionsResponseSchema = zod_1.z.array(exports.memberOptionSchema);
//# sourceMappingURL=members.dto.js.map