<?php
declare(strict_types=1);

return function (\App\Core\Database $db): void {
    $exists = $db->selectOne(
        "SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'sa_group_players' AND column_name = 'medical_grace_deadline'"
    );
    if (!$exists) {
        $db->raw("ALTER TABLE sa_group_players ADD COLUMN medical_grace_deadline DATE NULL DEFAULT NULL COMMENT 'Deadline for submitting medical cert' AFTER status");
    }

    $configExists = $db->selectOne("SELECT 1 FROM system_config WHERE config_key = 'sa.medical_grace_days'");
    if (!$configExists) {
        $db->raw("INSERT INTO system_config (config_key, config_value, config_group, label_ar, field_type, created_at, updated_at) VALUES ('sa.medical_grace_days', '14', 'sports_activity', 'مهلة تقديم الشهادة الطبية (بالأيام)', 'number', NOW(), NOW())");
    }
};
