<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_attendance` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `employee_profile_id`   BIGINT UNSIGNED NOT NULL,
            `attendance_date`       DATE NOT NULL,
            `check_in_time`         TIME NULL,
            `check_out_time`        TIME NULL,
            `check_in_method`       VARCHAR(20) NOT NULL DEFAULT 'manual' COMMENT 'manual, fingerprint, card, system',
            `check_out_method`      VARCHAR(20) NULL,
            `actual_hours`          DECIMAL(4,2) NULL,
            `overtime_hours`        DECIMAL(4,2) NOT NULL DEFAULT 0.00,
            `overtime_type`         VARCHAR(10) NOT NULL DEFAULT 'none' COMMENT 'none, day, night',
            `late_minutes`          INT UNSIGNED NOT NULL DEFAULT 0,
            `early_leave_minutes`   INT UNSIGNED NOT NULL DEFAULT 0,
            `status`                VARCHAR(20) NOT NULL COMMENT 'present, absent, late, leave, holiday, rest_day, half_day',
            `is_ramadan_schedule`   TINYINT(1) NOT NULL DEFAULT 0,
            `notes`                 TEXT NULL,
            `is_approved`           TINYINT(1) NOT NULL DEFAULT 0,
            `approved_by`           BIGINT UNSIGNED NULL,
            `approved_at`           TIMESTAMP NULL DEFAULT NULL,
            `created_at`            TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`            TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `created_by`            BIGINT UNSIGNED NULL,
            `updated_by`            BIGINT UNSIGNED NULL,
            `is_archived`           TINYINT(1) NOT NULL DEFAULT 0,
            `archived_at`           TIMESTAMP NULL DEFAULT NULL,
            `archived_by`           BIGINT UNSIGNED NULL,
            UNIQUE KEY `uq_hr_attendance_emp_date` (`employee_profile_id`, `attendance_date`),
            INDEX `idx_hr_attendance_date` (`attendance_date`),
            INDEX `idx_hr_attendance_status` (`status`),
            INDEX `idx_hr_attendance_employee` (`employee_profile_id`),
            CONSTRAINT `fk_hr_attendance_employee` FOREIGN KEY (`employee_profile_id`) REFERENCES `hr_employee_profiles`(`id`),
            CONSTRAINT `chk_hr_attendance_status` CHECK (`status` IN ('present', 'absent', 'late', 'leave', 'holiday', 'rest_day', 'half_day')),
            CONSTRAINT `chk_hr_attendance_ot_type` CHECK (`overtime_type` IN ('none', 'day', 'night'))
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `hr_attendance`",
];
