<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `parent_accounts` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `member_id` BIGINT UNSIGNED NULL COMMENT 'if parent is a club member',
            `full_name_ar` VARCHAR(200) NOT NULL,
            `full_name_en` VARCHAR(200) NULL,
            `phone` VARCHAR(30) NOT NULL,
            `secondary_phone` VARCHAR(30) NULL,
            `email` VARCHAR(200) NULL,
            `national_id` VARCHAR(20) NULL,
            `relationship` VARCHAR(20) NOT NULL DEFAULT 'parent' COMMENT 'parent, guardian, mother, father',
            `pin_hash` VARCHAR(255) NULL COMMENT 'for mobile app auth',
            `is_active` TINYINT(1) NOT NULL DEFAULT 1,
            `last_login_at` DATETIME NULL,
            `notification_preferences_json` JSON NULL,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            INDEX `idx_pa_member` (`member_id`),
            INDEX `idx_pa_phone` (`phone`),
            INDEX `idx_pa_active` (`is_active`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

        CREATE TABLE IF NOT EXISTS `parent_player_links` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `parent_id` BIGINT UNSIGNED NOT NULL,
            `player_id` BIGINT UNSIGNED NOT NULL,
            `relationship` VARCHAR(30) NOT NULL DEFAULT 'parent',
            `is_primary_contact` TINYINT(1) NOT NULL DEFAULT 0,
            `can_view_evaluations` TINYINT(1) NOT NULL DEFAULT 1,
            `can_view_attendance` TINYINT(1) NOT NULL DEFAULT 1,
            `can_view_medical` TINYINT(1) NOT NULL DEFAULT 1,
            `can_view_financials` TINYINT(1) NOT NULL DEFAULT 1,
            `can_approve_group_change` TINYINT(1) NOT NULL DEFAULT 0,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            UNIQUE KEY `uq_ppl_parent_player` (`parent_id`, `player_id`),
            INDEX `idx_ppl_player` (`player_id`),
            CONSTRAINT `fk_ppl_parent` FOREIGN KEY (`parent_id`) REFERENCES `parent_accounts`(`id`),
            CONSTRAINT `fk_ppl_player` FOREIGN KEY (`player_id`) REFERENCES `players`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

        CREATE TABLE IF NOT EXISTS `parent_notifications_log` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `parent_id` BIGINT UNSIGNED NOT NULL,
            `player_id` BIGINT UNSIGNED NULL,
            `notification_type` VARCHAR(50) NOT NULL COMMENT 'attendance, evaluation, medical, payment, schedule_change, injury, achievement',
            `title_ar` VARCHAR(300) NOT NULL,
            `body_ar` TEXT NOT NULL,
            `is_read` TINYINT(1) NOT NULL DEFAULT 0,
            `read_at` DATETIME NULL,
            `channel` VARCHAR(20) NOT NULL DEFAULT 'sms',
            `sent_at` DATETIME NULL,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            INDEX `idx_pnl_parent` (`parent_id`),
            INDEX `idx_pnl_player` (`player_id`),
            INDEX `idx_pnl_read` (`is_read`),
            INDEX `idx_pnl_type` (`notification_type`),
            CONSTRAINT `fk_pnl_parent` FOREIGN KEY (`parent_id`) REFERENCES `parent_accounts`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "
        DROP TABLE IF EXISTS `parent_notifications_log`;
        DROP TABLE IF EXISTS `parent_player_links`;
        DROP TABLE IF EXISTS `parent_accounts`
    ",
];
