<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `player_attendance` (
            `id`                BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `player_id`         BIGINT UNSIGNED NOT NULL,
            `enrollment_id`     BIGINT UNSIGNED NULL,
            `schedule_id`       BIGINT UNSIGNED NULL,
            `facility_id`       BIGINT UNSIGNED NULL,
            `attendance_date`   DATE NOT NULL,
            `check_in_time`     TIME NULL,
            `check_out_time`    TIME NULL,
            `status`            VARCHAR(20) NOT NULL DEFAULT 'present' COMMENT 'present, absent, late, excused',
            `notes`             TEXT 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,
            INDEX `idx_pa_player` (`player_id`),
            INDEX `idx_pa_enrollment` (`enrollment_id`),
            INDEX `idx_pa_schedule` (`schedule_id`),
            INDEX `idx_pa_facility` (`facility_id`),
            INDEX `idx_pa_date` (`attendance_date`),
            INDEX `idx_pa_player_date` (`player_id`, `attendance_date`),
            CONSTRAINT `fk_pa_player` FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_pa_enrollment` FOREIGN KEY (`enrollment_id`) REFERENCES `academy_enrollments`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_pa_schedule` FOREIGN KEY (`schedule_id`) REFERENCES `academy_schedules`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_pa_facility` FOREIGN KEY (`facility_id`) REFERENCES `facilities`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `player_attendance`",
];
