<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `coach_ratings` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `coach_id` BIGINT UNSIGNED NOT NULL,
            `player_id` BIGINT UNSIGNED NULL,
            `member_id` BIGINT UNSIGNED NULL,
            `session_id` BIGINT UNSIGNED NULL,
            `rating` TINYINT UNSIGNED NOT NULL COMMENT '1-5 stars',
            `punctuality_score` TINYINT UNSIGNED NULL COMMENT '1-5',
            `communication_score` TINYINT UNSIGNED NULL COMMENT '1-5',
            `technique_score` TINYINT UNSIGNED NULL COMMENT '1-5',
            `motivation_score` TINYINT UNSIGNED NULL COMMENT '1-5',
            `feedback_ar` TEXT NULL,
            `is_anonymous` TINYINT(1) NOT NULL DEFAULT 0,
            `status` VARCHAR(20) NOT NULL DEFAULT 'published' COMMENT 'published, hidden, flagged',
            `admin_response_ar` TEXT NULL,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            INDEX `idx_cr_coach` (`coach_id`),
            INDEX `idx_cr_player` (`player_id`),
            INDEX `idx_cr_rating` (`rating`),
            CONSTRAINT `fk_cr_coach` FOREIGN KEY (`coach_id`) REFERENCES `coaches`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

        CREATE TABLE IF NOT EXISTS `coach_performance_metrics` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `coach_id` BIGINT UNSIGNED NOT NULL,
            `period_month` VARCHAR(7) NOT NULL COMMENT 'YYYY-MM',
            `total_sessions_assigned` INT UNSIGNED NOT NULL DEFAULT 0,
            `total_sessions_conducted` INT UNSIGNED NOT NULL DEFAULT 0,
            `total_sessions_cancelled` INT UNSIGNED NOT NULL DEFAULT 0,
            `avg_attendance_rate` DECIMAL(5,2) NULL COMMENT 'percentage of enrolled who attended',
            `avg_rating` DECIMAL(3,2) NULL,
            `total_ratings_count` INT UNSIGNED NOT NULL DEFAULT 0,
            `total_players_trained` INT UNSIGNED NOT NULL DEFAULT 0,
            `player_retention_rate` DECIMAL(5,2) NULL COMMENT 'pct who continued next month',
            `punctuality_rate` DECIMAL(5,2) NULL COMMENT 'pct sessions started on time',
            `revenue_generated` DECIMAL(12,2) NOT NULL DEFAULT 0,
            `calculated_at` DATETIME NOT NULL,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            UNIQUE KEY `uq_cpm_coach_month` (`coach_id`, `period_month`),
            INDEX `idx_cpm_month` (`period_month`),
            CONSTRAINT `fk_cpm_coach` FOREIGN KEY (`coach_id`) REFERENCES `coaches`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "
        DROP TABLE IF EXISTS `coach_performance_metrics`;
        DROP TABLE IF EXISTS `coach_ratings`
    ",
];
