<?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 `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;

-- --------------------------------------------------------

--
-- Table structure for table `login_activity`
--


CREATE TABLE `login_activity` (

`id` int UNSIGNED NOT NULL,

  `user_id` int NOT NULL,

  `email` varchar(255) NOT NULL,

  `login_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

  `logout_time` timestamp NULL DEFAULT NULL,

  `ip_address` varchar(255) NOT NULL,

  `user_agent` varchar(255) NOT NULL,

  `created_at` datetime DEFAULT NULL,

  `updated_at` datetime DEFAULT NULL,

  `semester` varchar(255) NOT NULL,

  `school_year` varchar(9) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- --------------------------------------------------------

--
-- Table structure for table `longanswerquestions`
--


CREATE TABLE `longanswerquestions` (

`id` int NOT NULL,

  `la_question_id` int NOT NULL,

  `question_id` int NOT NULL,

  `correct_answer` text COLLATE utf8mb4_general_ci

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
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');
    }
};