"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.departmentsResponseSchema = exports.departmentResponseSchema = exports.updateDepartmentSchema = exports.createDepartmentSchema = exports.departmentMemberSchema = 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 departmentStatusSchema = zod_1.z.enum(['active', 'inactive', 'deleted']);
const memberStatusSchema = zod_1.z.enum([
    'active',
    'deactivated',
    'terminated',
    'deceased',
    'resigned',
    'deleted',
]);
const roleSchema = zod_1.z.enum(['owner', 'admin', 'member']);
exports.departmentMemberSchema = zod_1.z.object({
    id: zod_1.z.string().uuid().optional(),
    email: zod_1.z.string().email().optional(),
    employee_id: zod_1.z.string().optional(),
    image: zod_1.z.any().optional(),
    nickname: shared_dto_1.defaultTransformSchema,
    first_name: zod_1.z.string().optional(),
    last_name: shared_dto_1.defaultTransformSchema,
    role: roleSchema.optional(),
    status: memberStatusSchema.optional(),
    phone: shared_dto_1.defaultTransformSchema,
    work_phone: shared_dto_1.defaultTransformSchema,
    created_at: shared_dto_1.dateTransformSchema,
    updated_at: shared_dto_1.dateTransformSchema,
});
exports.createDepartmentSchema = zod_1.z.object({
    name: zod_1.z
        .string()
        .trim()
        .min(2, { message: 'Department name must be at least 2 characters long' }),
    department_code: zod_1.z
        .string()
        .trim()
        .min(1, { message: 'Department code is required' }),
    description: optionalString,
    department_head_id: optionalUuid,
    status: departmentStatusSchema.optional(),
});
exports.updateDepartmentSchema = exports.createDepartmentSchema
    .partial()
    .refine((data) => Object.keys(data).length > 0, {
    message: 'At least one field must be provided',
});
exports.departmentResponseSchema = zod_1.z.object({
    id: zod_1.z.string().uuid().optional(),
    name: zod_1.z.string().optional(),
    department_code: zod_1.z.string().optional(),
    description: shared_dto_1.defaultTransformSchema,
    department_head_id: zod_1.z.string().uuid().optional().nullable(),
    department_head: exports.departmentMemberSchema.optional().nullable(),
    members: zod_1.z.array(exports.departmentMemberSchema).optional(),
    members_count: zod_1.z.number().optional(),
    status: departmentStatusSchema.optional(),
    created_at: shared_dto_1.dateTransformSchema,
    updated_at: shared_dto_1.dateTransformSchema,
});
exports.departmentsResponseSchema = zod_1.z.array(exports.departmentResponseSchema);
//# sourceMappingURL=departments.dto.js.map