<?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
    {
        if (Schema::hasTable('late_slip_logs')) {
            return;
        }

        App\Support\SqliteCompat::statement(<<<'SQL'
CREATE TABLE `late_slip_logs` (
`id` int UNSIGNED NOT NULL,
  `school_year` varchar(32) DEFAULT NULL,
  `semester` varchar(32) DEFAULT NULL,
  `student_name` varchar(191) NOT NULL,
  `slip_date` date DEFAULT NULL,
  `time_in` time DEFAULT NULL,
  `grade` varchar(64) DEFAULT NULL,
  `reason` varchar(255) DEFAULT NULL,
  `admin_name` varchar(191) DEFAULT NULL,
  `printed_by` int DEFAULT NULL,
  `printed_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `late_slip_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `school_year` (`school_year`),
  ADD KEY `student_name` (`student_name`),
  ADD KEY `idx_late_slip_year_sem` (`school_year`,`semester`);
SQL
        );

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

    }

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