<?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->insert('system_config', [
            'config_key'     => 'sa.medical_grace_days',
            'config_value'   => '14',
            'config_type'    => 'integer',
            'group_name'     => 'sports_activity',
            'description_ar' => 'مهلة تقديم الشهادة الطبية (بالأيام)',
            'is_editable'    => 1,
            'created_at'     => date('Y-m-d H:i:s'),
            'updated_at'     => date('Y-m-d H:i:s'),
        ]);
    }
};
