"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cancelInterviewSchema = exports.scheduleInterviewSchema = exports.publicApiApplySchema = exports.jobPostingResponseSchema = exports.createTenantApiKeySchema = exports.publicApplySchema = exports.submitRecruitmentTaskSchema = exports.recruitmentTaskFilterSchema = exports.assignRecruitmentTasksSchema = exports.updateRecruitmentTaskSchema = exports.createRecruitmentTaskSchema = exports.jobApplicationFilterSchema = exports.bulkUpdateApplicationStatusSchema = exports.updateApplicationStatusSchema = exports.updateJobApplicationSchema = exports.createJobApplicationSchema = exports.jobPostingFilterSchema = exports.updateJobPostingSchema = exports.createJobPostingSchema = 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 optionalFileSchema = zod_1.z.any().optional();
const jobPostingStatusSchema = zod_1.z.enum(['draft', 'published', 'closed']);
const jobApplicationStatusSchema = zod_1.z.enum([
    'applied',
    'screening',
    'interview',
    'offer',
    'rejected',
    'hired',
    'archived',
]);
const paginationSchema = zod_1.z.object({
    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)),
    search: optionalString,
});
exports.createJobPostingSchema = zod_1.z.object({
    title: zod_1.z.string().trim().min(1, { message: 'Title is required' }),
    slug: zod_1.z.string().trim().min(1, { message: 'Slug is required' }),
    short_description: optionalString,
    salary_range: optionalString,
    location: optionalString,
    job_type: optionalString,
    experience: optionalString,
    department_id: optionalUuid,
    deadline: optionalDate,
    vacancy_count: zod_1.z.coerce.number().int().min(1).optional(),
    role_overview: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]).optional(),
    basics_benefits: zod_1.z.array(zod_1.z.string()).optional(),
    what_youll_do: zod_1.z.array(zod_1.z.string()).optional(),
    what_were_looking_for: zod_1.z.array(zod_1.z.string()).optional(),
    banner_image: shared_dto_1.imageSchema.nullable().optional(),
    icon_image: shared_dto_1.imageSchema.nullable().optional(),
    categories: zod_1.z.array(zod_1.z.string()).optional(),
    tags: zod_1.z.array(zod_1.z.string()).optional(),
    status: jobPostingStatusSchema.optional(),
});
exports.updateJobPostingSchema = exports.createJobPostingSchema.partial().refine((data) => Object.keys(data).length > 0, { message: 'At least one field must be provided' });
exports.jobPostingFilterSchema = paginationSchema.extend({
    status: jobPostingStatusSchema.optional(),
    department_id: optionalUuid,
    sort: zod_1.z.enum(['newest', 'oldest', 'title']).optional(),
});
exports.createJobApplicationSchema = zod_1.z.object({
    job_posting_id: zod_1.z.string().uuid({ message: 'Job posting is required' }),
    full_name: zod_1.z.string().trim().min(1, { message: 'Full name is required' }),
    email: zod_1.z.string().email({ message: 'Valid email is required' }),
    phone: optionalString,
    location: optionalString,
    photo_url: shared_dto_1.imageSchema.nullable().optional(),
    experience_years: zod_1.z.coerce.number().int().min(0).optional(),
    resume: optionalFileSchema,
    skills: zod_1.z.array(zod_1.z.string()).optional(),
    work_history: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.any())).optional(),
    notes: optionalString,
    source: zod_1.z.enum(['public_form', 'public_api', 'manual']).optional(),
    status: jobApplicationStatusSchema.optional(),
    template_id: optionalString,
    start_date: optionalDate,
});
exports.updateJobApplicationSchema = zod_1.z
    .object({
    full_name: optionalString,
    email: zod_1.z.string().email().optional(),
    phone: optionalString,
    location: optionalString,
    photo_url: shared_dto_1.imageSchema.nullable().optional(),
    experience_years: zod_1.z.coerce.number().int().min(0).optional(),
    resume: optionalFileSchema,
    skills: zod_1.z.array(zod_1.z.string()).optional(),
    work_history: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.any())).optional(),
    notes: optionalString,
    status: jobApplicationStatusSchema.optional(),
    interview_at: optionalDate,
    offer_status: optionalString,
    start_date: optionalDate,
    template_id: optionalString,
})
    .refine((data) => Object.keys(data).length > 0, {
    message: 'At least one field must be provided',
});
exports.updateApplicationStatusSchema = zod_1.z.object({
    status: jobApplicationStatusSchema,
    interview_at: optionalDate,
    offer_status: optionalString,
    start_date: optionalDate,
    template_id: optionalString,
});
exports.bulkUpdateApplicationStatusSchema = zod_1.z.object({
    ids: zod_1.z.array(zod_1.z.string().uuid()).min(1),
    status: jobApplicationStatusSchema,
});
exports.jobApplicationFilterSchema = paginationSchema.extend({
    job_posting_id: optionalUuid,
    status: jobApplicationStatusSchema.optional(),
    source: zod_1.z.enum(['public_form', 'public_api', 'manual']).optional(),
    start_date: optionalDate,
    end_date: optionalDate,
    sort: zod_1.z.enum(['newest', 'oldest', 'name']).optional(),
    include_terminal: zod_1.z.preprocess((value) => {
        if (value === 'true' || value === true)
            return true;
        if (value === 'false' || value === false)
            return false;
        return undefined;
    }, zod_1.z.boolean().optional()),
});
exports.createRecruitmentTaskSchema = zod_1.z.object({
    application_id: zod_1.z
        .preprocess((val) => {
        if (val === "00000000-0000-0000-0000-000000000000" ||
            val === "" ||
            val === null ||
            val === undefined)
            return null;
        return val;
    }, zod_1.z.string().uuid().nullable().optional())
        .optional(),
    title: zod_1.z.string().trim().min(1),
    description: optionalString,
    due_date: optionalDate,
    files: zod_1.z.array(zod_1.z.any()).optional(),
});
exports.updateRecruitmentTaskSchema = exports.createRecruitmentTaskSchema.partial();
exports.assignRecruitmentTasksSchema = zod_1.z.object({
    task_id: zod_1.z.string().uuid(),
    application_ids: zod_1.z.array(zod_1.z.string().uuid()).min(1),
});
exports.recruitmentTaskFilterSchema = paginationSchema.extend({
    application_id: optionalUuid,
    status: zod_1.z.enum(['pending', 'submitted', 'reviewed']).optional(),
});
exports.submitRecruitmentTaskSchema = zod_1.z.object({
    text: optionalString,
    files: zod_1.z.array(zod_1.z.any()).optional(),
});
exports.publicApplySchema = zod_1.z.object({
    full_name: zod_1.z.string().trim().min(1),
    email: zod_1.z.string().email(),
    phone: optionalString,
    location: optionalString,
    experience_years: zod_1.z.coerce.number().int().min(0).optional(),
    resume: optionalFileSchema,
    skills: zod_1.z.array(zod_1.z.string()).optional(),
    work_history: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.any())).optional(),
});
exports.createTenantApiKeySchema = zod_1.z.object({
    name: zod_1.z.string().trim().min(1),
});
exports.jobPostingResponseSchema = zod_1.z.object({
    id: zod_1.z.string().uuid(),
    title: zod_1.z.string(),
    slug: zod_1.z.string(),
    short_description: shared_dto_1.defaultTransformSchema,
    salary_range: shared_dto_1.defaultTransformSchema,
    location: shared_dto_1.defaultTransformSchema,
    job_type: shared_dto_1.defaultTransformSchema,
    experience: shared_dto_1.defaultTransformSchema,
    department_id: zod_1.z.string().uuid().nullable().optional(),
    deadline: shared_dto_1.dateTransformSchema.nullable().optional(),
    vacancy_count: zod_1.z.number(),
    role_overview: zod_1.z.any().optional(),
    basics_benefits: zod_1.z.any().optional(),
    what_youll_do: zod_1.z.any().optional(),
    what_were_looking_for: zod_1.z.any().optional(),
    banner_image: shared_dto_1.imageSchema.nullable().optional(),
    icon_image: shared_dto_1.imageSchema.nullable().optional(),
    categories: zod_1.z.any().optional(),
    tags: zod_1.z.any().optional(),
    status: jobPostingStatusSchema,
    record_status: zod_1.z.enum(['active', 'inactive', 'deleted']).optional(),
    owner_id: zod_1.z.string().uuid(),
    created_at: shared_dto_1.dateTransformSchema,
    updated_at: shared_dto_1.dateTransformSchema,
    department: zod_1.z
        .object({
        id: zod_1.z.string().uuid(),
        name: zod_1.z.string(),
    })
        .nullable()
        .optional(),
    owner: zod_1.z
        .object({
        id: zod_1.z.string().uuid(),
        slug: zod_1.z.string().nullable(),
        name: zod_1.z.string(),
    })
        .optional(),
});
exports.publicApiApplySchema = exports.publicApplySchema.extend({
    job_posting_id: zod_1.z.string().uuid({ message: 'Job posting is required' }),
});
exports.scheduleInterviewSchema = zod_1.z.object({
    application_ids: zod_1.z
        .array(zod_1.z.string().uuid())
        .min(1, { message: 'At least one candidate is required' }),
    subject: zod_1.z.string().trim().min(1, { message: 'Subject is required' }),
    interview_date: zod_1.z
        .string()
        .trim()
        .min(1, { message: 'Interview date is required' }),
    interview_time: zod_1.z
        .string()
        .trim()
        .min(1, { message: 'Interview time is required' }),
    timezone: optionalString,
    interview_type: optionalString,
    platform_name: optionalString,
    duration: optionalString,
    meeting_link: optionalString,
    interviewers: zod_1.z.array(zod_1.z.string()).optional(),
    instructions: optionalString,
    send_email: zod_1.z.boolean().optional(),
});
exports.cancelInterviewSchema = zod_1.z.object({
    application_ids: zod_1.z
        .array(zod_1.z.string().uuid())
        .min(1, { message: 'At least one candidate is required' }),
    send_email: zod_1.z.boolean().optional(),
    reason: optionalString,
});
//# sourceMappingURL=recruitment.dto.js.map