"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.attendanceReportResponseArraySchema = exports.attendanceReportResponseSchema = exports.todayAttendancesResponseSchema = exports.todayAttendanceItemSchema = exports.qrScanResultResponseSchema = exports.qrPointListResponseSchema = exports.qrPointResponseSchema = exports.attendancesResponseSchema = exports.attendanceResponseSchema = exports.attendanceMemberSchema = exports.attendanceReportFilterSchema = exports.attendanceFilterSchema = exports.adminManualAttendanceSchema = exports.updateQrPointSchema = exports.createQrPointSchema = exports.scanQrAttendanceSchema = exports.teacherCheckOutSchema = exports.teacherCheckInSchema = exports.attendanceStatusSchema = exports.attendanceTypeSchema = void 0;
const zod_1 = require("zod");
const shared_dto_1 = require("../shared/shared.dto");
exports.attendanceTypeSchema = zod_1.z.enum([
    'in_office',
    'remote',
    'on_duty',
    'flexible',
    'on_leave',
]);
exports.attendanceStatusSchema = zod_1.z.enum([
    'present',
    'absent',
    'late',
    'half_day',
    'on_leave',
    'remote',
    'check_in',
    'on_break',
    'holiday',
    'weekend',
    'all',
]);
const geoCoordinateSchema = zod_1.z
    .union([zod_1.z.number(), zod_1.z.string()])
    .transform((val) => val === null || val === undefined || val === '' ? undefined : Number(val))
    .optional();
exports.teacherCheckInSchema = zod_1.z.object({
    device_id: zod_1.z.string().min(1, 'Device ID is required'),
    device_name: zod_1.z.string().optional(),
    note: zod_1.z.string().optional(),
    latitude: geoCoordinateSchema,
    longitude: geoCoordinateSchema,
    accuracy: zod_1.z.number().optional(),
});
exports.teacherCheckOutSchema = zod_1.z.object({
    device_id: zod_1.z.string().min(1, 'Device ID is required'),
    note: zod_1.z.string().optional(),
    latitude: geoCoordinateSchema,
    longitude: geoCoordinateSchema,
    accuracy: zod_1.z.number().optional(),
});
exports.scanQrAttendanceSchema = zod_1.z.object({
    qr_code: zod_1.z.string().min(1, 'QR code is required'),
    device_id: zod_1.z.string().min(1, 'Device ID is required'),
    device_name: zod_1.z.string().optional(),
    note: zod_1.z.string().optional(),
    latitude: geoCoordinateSchema,
    longitude: geoCoordinateSchema,
    accuracy: zod_1.z.number().optional(),
});
exports.createQrPointSchema = zod_1.z.object({
    label: zod_1.z.string().min(1, 'Label is required'),
    is_active: zod_1.z.boolean().optional().default(true),
});
exports.updateQrPointSchema = zod_1.z.object({
    label: zod_1.z.string().optional(),
    is_active: zod_1.z.boolean().optional(),
});
exports.adminManualAttendanceSchema = zod_1.z.object({
    member_id: zod_1.z.string().uuid('Invalid member ID'),
    date: zod_1.z.string().or(zod_1.z.date()),
    check_in: zod_1.z.string().or(zod_1.z.date()).optional().nullable(),
    check_out: zod_1.z.string().or(zod_1.z.date()).optional().nullable(),
    status: exports.attendanceStatusSchema.optional().default('present'),
    work_hours: zod_1.z.number().optional(),
    break_hours: zod_1.z.number().optional(),
    net_hours: zod_1.z.number().optional(),
    overtime_hours: zod_1.z.number().optional(),
    note: zod_1.z.string().optional(),
});
exports.attendanceFilterSchema = zod_1.z.object({
    page: zod_1.z.coerce.number().optional(),
    limit: zod_1.z.coerce.number().optional(),
    data_scope: zod_1.z.enum(['all', 'own']).optional(),
    member_id: zod_1.z.string().uuid().optional(),
    department_id: zod_1.z.string().uuid().optional(),
    date: shared_dto_1.optionalDate,
    from: shared_dto_1.optionalDate,
    to: shared_dto_1.optionalDate,
    month_year: shared_dto_1.optionalDate,
    status: exports.attendanceStatusSchema.optional().default('all'),
    search: zod_1.z.string().optional(),
});
exports.attendanceReportFilterSchema = zod_1.z.object({
    start_date: shared_dto_1.optionalDate,
    end_date: shared_dto_1.optionalDate,
    department_id: zod_1.z.string().uuid().optional(),
    search: zod_1.z.string().optional(),
});
exports.attendanceMemberSchema = zod_1.z.object({
    id: zod_1.z.string().uuid(),
    first_name: zod_1.z.string(),
    last_name: shared_dto_1.defaultTransformSchema,
    nickname: shared_dto_1.defaultTransformSchema,
    employee_id: zod_1.z.string(),
    role: zod_1.z.enum(['owner', 'admin', 'member']).optional(),
    image: shared_dto_1.imageSchema.optional(),
    department: zod_1.z
        .object({
        id: zod_1.z.string().uuid(),
        name: zod_1.z.string(),
    })
        .optional()
        .nullable(),
});
exports.attendanceResponseSchema = zod_1.z.object({
    id: zod_1.z.string().uuid(),
    member_id: zod_1.z.string().uuid(),
    member: exports.attendanceMemberSchema.optional(),
    date: zod_1.z
        .union([zod_1.z.date(), zod_1.z.string()])
        .transform((d) => (d instanceof Date ? d.toISOString().substring(0, 10) : String(d)))
        .optional(),
    type: zod_1.z.string().optional(),
    check_in: zod_1.z
        .date()
        .transform((date) => date.toISOString())
        .optional()
        .nullable(),
    check_out: zod_1.z
        .date()
        .transform((date) => date.toISOString())
        .optional()
        .nullable(),
    work_hours: zod_1.z.number().optional().nullable(),
    break_hours: zod_1.z.number().optional().nullable(),
    net_hours: zod_1.z.number().optional().nullable(),
    overtime_hours: zod_1.z.number().optional().nullable(),
    status: exports.attendanceStatusSchema.optional(),
    check_in_ip: shared_dto_1.nullableDefaultTransformSchema,
    check_out_ip: shared_dto_1.nullableDefaultTransformSchema,
    device_id: shared_dto_1.nullableDefaultTransformSchema,
    attendance_method: zod_1.z.string().optional(),
    qr_point_id: shared_dto_1.nullableDefaultTransformSchema,
    check_in_latitude: zod_1.z
        .union([zod_1.z.number(), zod_1.z.string()])
        .transform((val) => val === null || val === undefined ? null : Number(val))
        .nullable()
        .optional(),
    check_in_longitude: zod_1.z
        .union([zod_1.z.number(), zod_1.z.string()])
        .transform((val) => val === null || val === undefined ? null : Number(val))
        .nullable()
        .optional(),
    check_in_distance_meters: zod_1.z.number().nullable().optional(),
    check_out_latitude: zod_1.z
        .union([zod_1.z.number(), zod_1.z.string()])
        .transform((val) => val === null || val === undefined ? null : Number(val))
        .nullable()
        .optional(),
    check_out_longitude: zod_1.z
        .union([zod_1.z.number(), zod_1.z.string()])
        .transform((val) => val === null || val === undefined ? null : Number(val))
        .nullable()
        .optional(),
    check_out_distance_meters: zod_1.z.number().nullable().optional(),
    note: shared_dto_1.defaultTransformSchema,
    created_at: shared_dto_1.dateTransformSchema,
    updated_at: shared_dto_1.dateTransformSchema,
});
exports.attendancesResponseSchema = zod_1.z.array(exports.attendanceResponseSchema);
exports.qrPointResponseSchema = zod_1.z.object({
    id: zod_1.z.string().uuid(),
    owner_id: zod_1.z.string(),
    label: zod_1.z.string(),
    code: zod_1.z.string(),
    is_active: zod_1.z.boolean(),
    qr_data_url: zod_1.z.string().optional(),
    created_at: shared_dto_1.dateTransformSchema,
    updated_at: shared_dto_1.dateTransformSchema,
});
exports.qrPointListResponseSchema = zod_1.z.array(exports.qrPointResponseSchema);
exports.qrScanResultResponseSchema = zod_1.z.object({
    action: zod_1.z.enum(['CHECK_IN', 'CHECK_OUT', 'ALREADY_COMPLETED']),
    status: exports.attendanceStatusSchema.optional(),
    check_in: zod_1.z.string().optional().nullable(),
    check_out: zod_1.z.string().optional().nullable(),
    work_hours: zod_1.z.number().optional().nullable(),
    break_hours: zod_1.z.number().optional().nullable(),
    net_hours: zod_1.z.number().optional().nullable(),
    overtime_hours: zod_1.z.number().optional().nullable(),
    attendance: exports.attendanceResponseSchema.optional().nullable(),
    message: zod_1.z.string(),
});
exports.todayAttendanceItemSchema = zod_1.z.object({
    member: exports.attendanceMemberSchema,
    date: shared_dto_1.optionalDate,
    status: exports.attendanceStatusSchema,
    is_submitted: zod_1.z.boolean(),
    attendance: exports.attendanceResponseSchema.nullable(),
});
exports.todayAttendancesResponseSchema = zod_1.z.array(exports.todayAttendanceItemSchema);
exports.attendanceReportResponseSchema = zod_1.z.object({
    id: zod_1.z.string().uuid(),
    first_name: zod_1.z.string(),
    last_name: shared_dto_1.defaultTransformSchema,
    nickname: shared_dto_1.defaultTransformSchema,
    employee_id: zod_1.z.string(),
    role: zod_1.z.enum(['owner', 'admin', 'member']).optional(),
    image: shared_dto_1.imageSchema.optional(),
    department: zod_1.z
        .object({
        id: zod_1.z.string().uuid(),
        name: zod_1.z.string(),
    })
        .optional()
        .nullable(),
    attendance_count: zod_1.z.number(),
    late_count: zod_1.z.number(),
    half_day_count: zod_1.z.number(),
    leave_count: zod_1.z.number(),
    absent_count: zod_1.z.number(),
    total_working_days: zod_1.z.number(),
    total_working_hours: zod_1.z.number(),
    total_net_hours: zod_1.z.number().optional(),
    total_overtime: zod_1.z.number(),
    attendance_percentage: zod_1.z.number().optional(),
    attendances: zod_1.z.array(exports.attendanceResponseSchema),
});
exports.attendanceReportResponseArraySchema = zod_1.z.array(exports.attendanceReportResponseSchema);
//# sourceMappingURL=attendance.dto.js.map