<?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 `class_progress_reports` (
`id` int UNSIGNED NOT NULL,
  `class_section_id` int UNSIGNED NOT NULL,
  `teacher_id` int UNSIGNED NOT NULL,
  `week_start` date NOT NULL,
  `week_end` date NOT NULL,
  `subject` varchar(160) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `unit_title` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `materials` varchar(160) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `covered` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `homework` text COLLATE utf8mb4_unicode_ci,
  `assessment` text COLLATE utf8mb4_unicode_ci,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status_notes` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `class_notes` text COLLATE utf8mb4_unicode_ci,
  `next_week_plan` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `support_needed` text COLLATE utf8mb4_unicode_ci,
  `flags_json` text COLLATE utf8mb4_unicode_ci,
  `attachment_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `class_progress_reports`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_class_week` (`class_section_id`,`week_start`,`week_end`);
SQL
        );

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

    }

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