<?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 `print_requests` (
`id` int UNSIGNED NOT NULL,
  `teacher_id` int UNSIGNED NOT NULL,
  `admin_id` int UNSIGNED DEFAULT NULL,
  `class_id` int UNSIGNED NOT NULL,
  `file_path` varchar(255) NOT NULL,
  `page_selection` varchar(255) DEFAULT NULL,
  `num_copies` int NOT NULL,
  `required_by` datetime NOT NULL,
  `pickup_method` varchar(255) NOT NULL,
  `status` enum('not_assigned','assigned','done','delivered') NOT NULL DEFAULT 'not_assigned',
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

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

--
-- Table structure for table `project`
--


CREATE TABLE `project` (

`id` int UNSIGNED NOT NULL,

  `student_id` int NOT NULL,

  `school_id` char(36) NOT NULL,

  `class_section_id` int DEFAULT NULL,

  `updated_by` int NOT NULL,

  `project_index` tinyint DEFAULT NULL,

  `score` float DEFAULT NULL,

  `comment` text,

  `semester` varchar(25) NOT NULL,

  `school_year` varchar(9) DEFAULT NULL,

  `created_at` datetime DEFAULT NULL,

  `updated_at` datetime DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

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

--
-- Table structure for table `promotion_queue`
--


CREATE TABLE `promotion_queue` (

`id` int UNSIGNED NOT NULL,

  `student_id` int UNSIGNED NOT NULL,

  `from_class_section_id` int UNSIGNED DEFAULT NULL,

  `to_class_id` int UNSIGNED NOT NULL,

  `to_class_section_id` int UNSIGNED DEFAULT NULL,

  `school_year_from` varchar(9) NOT NULL,

  `school_year_to` varchar(9) NOT NULL,

  `status` enum('queued','assigned','applied','cancelled') NOT NULL DEFAULT 'queued',

  `created_at` datetime DEFAULT NULL,

  `updated_at` datetime DEFAULT NULL,

  `updated_by` int UNSIGNED DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

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

--
-- Table structure for table `qcmquestions`
--


CREATE TABLE `qcmquestions` (

`id` int NOT NULL,

  `qcm_question_id` int NOT NULL,

  `question_id` int NOT NULL,

  `answer_a` text COLLATE utf8mb4_unicode_ci NOT NULL,

  `answer_b` text COLLATE utf8mb4_unicode_ci NOT NULL,

  `answer_c` text COLLATE utf8mb4_unicode_ci,

  `answer_d` text COLLATE utf8mb4_unicode_ci,

  `answer_e` text COLLATE utf8mb4_unicode_ci,

  `correct_answer` char(1) COLLATE utf8mb4_unicode_ci DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `print_requests`
  ADD PRIMARY KEY (`id`),
  ADD KEY `print_requests_teacher_id_foreign` (`teacher_id`),
  ADD KEY `print_requests_admin_id_foreign` (`admin_id`),
  ADD KEY `print_requests_class_id_foreign` (`class_id`);
SQL
        );

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

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `print_requests`
  ADD CONSTRAINT `print_requests_admin_id_foreign` FOREIGN KEY (`admin_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `print_requests_teacher_id_foreign` FOREIGN KEY (`teacher_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
SQL
        );

    }

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