<?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 `parent_attendance_reports` (
`id` int UNSIGNED NOT NULL,
  `parent_id` int UNSIGNED NOT NULL COMMENT 'users.id of the reporting parent (primary parent id)',
  `student_id` int UNSIGNED NOT NULL,
  `class_section_id` int UNSIGNED DEFAULT NULL,
  `report_date` date NOT NULL,
  `type` enum('absent','late','early_dismissal') NOT NULL DEFAULT 'absent',
  `arrival_time` time DEFAULT NULL,
  `dismiss_time` time DEFAULT NULL,
  `reason` text,
  `semester` varchar(32) DEFAULT NULL,
  `school_year` varchar(16) DEFAULT NULL,
  `status` enum('new','seen','processed') NOT NULL DEFAULT 'new',
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

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

--
-- Table structure for table `parent_meeting_schedules`
--


CREATE TABLE `parent_meeting_schedules` (

`id` int UNSIGNED NOT NULL,

  `student_id` int UNSIGNED NOT NULL,

  `parent_user_id` int UNSIGNED NOT NULL,

  `parent_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,

  `student_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,

  `class_section_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,

  `date` date NOT NULL,

  `time` time NOT NULL,

  `notes` text COLLATE utf8mb4_unicode_ci,

  `semester` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,

  `school_year` varchar(9) COLLATE utf8mb4_unicode_ci NOT NULL,

  `status` enum('pending','approved','rejected','cancelled','completed') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending',

  `created_by` int UNSIGNED 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=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `parent_attendance_reports`
  ADD PRIMARY KEY (`id`),
  ADD KEY `parent_attendance_reports_parent_id_foreign` (`parent_id`),
  ADD KEY `report_date` (`report_date`),
  ADD KEY `student_id_report_date` (`student_id`,`report_date`);
SQL
        );

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

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `parent_attendance_reports`
  ADD CONSTRAINT `parent_attendance_reports_parent_id_foreign` FOREIGN KEY (`parent_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `parent_attendance_reports_student_id_foreign` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
SQL
        );

    }

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