<?php
declare(strict_types=1);

use App\Core\Database;

return function (Database $db): void {
    $cols = [
        'target_spouses_count'  => "ALTER TABLE transfer_requests ADD COLUMN target_spouses_count INT UNSIGNED NULL DEFAULT NULL AFTER target_companions_count",
        'target_children_count' => "ALTER TABLE transfer_requests ADD COLUMN target_children_count INT UNSIGNED NULL DEFAULT NULL AFTER target_spouses_count",
        'target_temps_count'    => "ALTER TABLE transfer_requests ADD COLUMN target_temps_count INT UNSIGNED NULL DEFAULT NULL AFTER target_children_count",
        'marriage_date'         => "ALTER TABLE transfer_requests ADD COLUMN marriage_date DATE NULL DEFAULT NULL AFTER work_date",
    ];

    foreach ($cols as $col => $sql) {
        $exists = $db->selectOne(
            "SELECT 1 FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'transfer_requests' AND column_name = ?",
            [$col]
        );
        if (!$exists) {
            $db->raw($sql);
        }
    }
};
