<?php
declare(strict_types=1);

return [
    'up' => "CREATE TABLE IF NOT EXISTS `academy_settlements` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `settlement_number` VARCHAR(50) NOT NULL,
    `academy_id` BIGINT UNSIGNED NOT NULL,
    `contract_id` BIGINT UNSIGNED NOT NULL,
    `period_month` VARCHAR(7) NOT NULL,
    `total_revenue` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `minimum_guarantee` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `revenue_surplus` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `revenue_shortfall` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `club_commission` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `academy_share` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `net_amount` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `penalty_amount` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `direction` VARCHAR(20) NOT NULL COMMENT 'club_pays_academy, academy_pays_club, balanced',
    `status` VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft, pending_approval, approved, paid, disputed',
    `approved_by` BIGINT UNSIGNED NULL,
    `approved_at` TIMESTAMP NULL,
    `payment_id` BIGINT UNSIGNED NULL,
    `paid_at` TIMESTAMP NULL,
    `dispute_reason` TEXT NULL,
    `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,
    UNIQUE KEY `uq_as_number` (`settlement_number`),
    INDEX `idx_as_academy_month` (`academy_id`, `period_month`),
    INDEX `idx_as_contract` (`contract_id`),
    INDEX `idx_as_status` (`status`),
    CONSTRAINT `fk_as2_academy` FOREIGN KEY (`academy_id`) REFERENCES `academies`(`id`) ON DELETE RESTRICT,
    CONSTRAINT `fk_as2_contract` FOREIGN KEY (`contract_id`) REFERENCES `academy_contracts`(`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
    'down' => "DROP TABLE IF EXISTS `academy_settlements`",
];
