<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        App\Support\SqliteCompat::statement(<<<'SQL'
CREATE TABLE `competition_winners` (
`id` int UNSIGNED NOT NULL,
  `competition_id` int UNSIGNED NOT NULL,
  `student_id` int UNSIGNED NOT NULL,
  `class_section_id` int DEFAULT NULL,
  `rank` int NOT NULL,
  `score` decimal(6,2) NOT NULL DEFAULT '0.00',
  `prize_amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `created_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `competition_winners`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `competition_id_class_section_id_student_id` (`competition_id`,`class_section_id`,`student_id`),
  ADD KEY `competition_id` (`competition_id`),
  ADD KEY `class_section_id` (`class_section_id`),
  ADD KEY `competition_id_class_section_id_rank` (`competition_id`,`class_section_id`,`rank`);
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `competition_winners`
  MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;
SQL
        );

    }

    public function down(): void
    {
        Schema::dropIfExists('competition_winners');
    }
};