<?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 `attendance_tracking` (
`id` int UNSIGNED NOT NULL,
  `student_id` int UNSIGNED NOT NULL,
  `date` datetime NOT NULL,
  `is_reported` enum('no','yes') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'no',
  `reason` text COLLATE utf8mb4_general_ci,
  `note` text COLLATE utf8mb4_general_ci,
  `is_notified` tinyint(1) NOT NULL DEFAULT '0',
  `notif_counter` int UNSIGNED NOT NULL DEFAULT '0',
  `semester` varchar(16) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `school_year` varchar(9) COLLATE utf8mb4_general_ci DEFAULT 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 `attendance_tracking`
  ADD PRIMARY KEY (`id`),
  ADD KEY `student_id` (`student_id`);
SQL
        );

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

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `attendance_tracking`
  ADD CONSTRAINT `attendance_tracking_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
SQL
        );

    }

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