<?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 `enrollments` (
`id` int UNSIGNED NOT NULL,
  `student_id` int UNSIGNED NOT NULL,
  `class_section_id` int UNSIGNED DEFAULT NULL,
  `parent_id` int UNSIGNED NOT NULL,
  `enrollment_date` date NOT NULL,
  `enrollment_status` enum('admission under review','payment pending','enrolled','withdraw under review','refund pending','withdrawn','waitlist','denied') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'admission under review',
  `withdrawal_date` date DEFAULT NULL,
  `is_withdrawn` tinyint(1) NOT NULL DEFAULT '0',
  `admission_status` enum('pending','accepted','denied') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'pending',
  `semester` varchar(25) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `school_year` varchar(25) COLLATE utf8mb4_general_ci NOT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `enrollments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `student_id` (`student_id`),
  ADD KEY `class_section_id` (`class_section_id`),
  ADD KEY `parent_id` (`parent_id`);
SQL
        );

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

    }

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