<?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 `teacher_attendance_data` (
`id` int UNSIGNED NOT NULL,
  `class_section_id` int UNSIGNED NOT NULL,
  `teacher_id` int UNSIGNED NOT NULL,
  `position` enum('main','ta') NOT NULL,
  `date` date NOT NULL,
  `semester` varchar(25) NOT NULL,
  `school_year` varchar(25) NOT NULL,
  `status` enum('present','absent','late') NOT NULL,
  `reason` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `teacher_attendance_data`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_teacher_att` (`class_section_id`,`teacher_id`,`date`,`semester`,`school_year`),
  ADD KEY `idx_att_by_day` (`class_section_id`,`date`,`semester`,`school_year`),
  ADD KEY `fk_tatt_user` (`teacher_id`);
SQL
        );

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

    }

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