<?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 `subject_curriculum_items` (
`id` int UNSIGNED NOT NULL,
  `class_id` int UNSIGNED NOT NULL,
  `subject` enum('islamic','quran') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'islamic',
  `unit_number` smallint DEFAULT NULL,
  `unit_title` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `chapter_name` varchar(255) 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 `subject_curriculum_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_class_subject` (`class_id`,`subject`);
SQL
        );

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

    }

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