<?php

namespace Database\Seeders;

use App\Models\AcademicEvent;
use App\Models\AcademicYear;
use App\Models\SchoolHoliday;
use Illuminate\Database\Seeder;

class AcademicCalendarSeeder extends Seeder
{
    public function run(): void
    {
        $year = AcademicYear::updateOrCreate(
            ['name' => '2026/2027'],
            [
                'start_date' => '2026-07-14',
                'end_date' => '2027-06-19',
                'is_active' => true,
            ]
        );

        AcademicYear::updateOrCreate(
            ['name' => '2025/2026'],
            [
                'start_date' => '2025-07-14',
                'end_date' => '2026-06-20',
                'is_active' => false,
            ]
        );

        $holidays = [
            ['name' => 'Hari Kemerdekaan RI', 'date' => '2026-08-17', 'type' => 'national', 'description' => 'Libur nasional 17 Agustus'],
            ['name' => 'Maulid Nabi Muhammad SAW', 'date' => '2026-08-25', 'type' => 'national', 'description' => 'Libur nasional Maulid Nabi'],
            ['name' => 'Hari Guru Nasional', 'date' => '2026-11-25', 'type' => 'school', 'description' => 'Libur sekolah Hari Guru'],
            ['name' => 'Libur Semester Ganjil', 'date' => '2026-12-21', 'type' => 'school', 'description' => 'Awal libur semester ganjil'],
            ['name' => 'Tahun Baru Masehi', 'date' => '2027-01-01', 'type' => 'national', 'description' => 'Libur nasional Tahun Baru'],
            ['name' => 'Hari Raya Idul Fitri', 'date' => '2027-03-10', 'type' => 'national', 'description' => 'Libur Idul Fitri'],
            ['name' => 'Hari Pendidikan Nasional', 'date' => '2027-05-02', 'type' => 'national', 'description' => 'Libur nasional Hardiknas'],
            ['name' => 'Hari Raya Idul Adha', 'date' => '2027-05-17', 'type' => 'national', 'description' => 'Libur Idul Adha'],
        ];

        foreach ($holidays as $holiday) {
            SchoolHoliday::updateOrCreate(
                [
                    'academic_year_id' => $year->id,
                    'date' => $holiday['date'],
                ],
                [
                    'name' => $holiday['name'],
                    'type' => $holiday['type'],
                    'description' => $holiday['description'],
                ]
            );
        }

        $events = [
            [
                'title' => 'MPLS Tahun Ajaran 2026/2027',
                'type' => 'mpls',
                'start_date' => '2026-07-14',
                'end_date' => '2026-07-18',
                'description' => 'Masa Pengenalan Lingkungan Sekolah bagi siswa baru',
            ],
            [
                'title' => 'Ujian Tengah Semester Ganjil',
                'type' => 'ujian',
                'start_date' => '2026-09-21',
                'end_date' => '2026-09-26',
                'description' => 'UTS semester ganjil untuk seluruh kelas',
            ],
            [
                'title' => 'Praktik Kerja Lapangan (PKL) Kelas XI',
                'type' => 'pkl',
                'start_date' => '2026-10-05',
                'end_date' => '2026-12-05',
                'description' => 'PKL siswa kelas XI di industri mitra',
            ],
            [
                'title' => 'Ujian Akhir Semester Ganjil',
                'type' => 'ujian',
                'start_date' => '2026-12-07',
                'end_date' => '2026-12-12',
                'description' => 'UAS semester ganjil',
            ],
            [
                'title' => 'Rapat Koordinasi Guru',
                'type' => 'khusus',
                'start_date' => '2026-08-08',
                'end_date' => '2026-08-08',
                'description' => 'Rapat koordinasi awal bulan Agustus',
            ],
        ];

        foreach ($events as $event) {
            AcademicEvent::updateOrCreate(
                [
                    'academic_year_id' => $year->id,
                    'title' => $event['title'],
                ],
                $event + ['academic_year_id' => $year->id]
            );
        }
    }
}
