<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('m_holidays', function (Blueprint $table) {
            $table->id();
            $table->string('name', 255);
            $table->date('date');
            $table->enum('type', ['National', 'Religious', 'Company', 'Regional'])->default('Company');
            $table->text('description')->nullable();
            $table->boolean('is_recurring')->default(false);
            $table->enum('recurring_type', ['None', 'Yearly', 'Monthly'])->default('None');
            $table->boolean('is_active')->default(true);
            $table->boolean('delete_flag')->default(false);
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->timestamps();

            $table->index(['delete_flag', 'is_active']);
            $table->index(['date', 'is_active']);
            $table->index('type');
        });

        // Insert sample holidays for 2024-2025
        DB::table('m_holidays')->insert([
            // 2024 Holidays
            [
                'name' => 'New Year\'s Day',
                'date' => '2024-01-01',
                'type' => 'National',
                'description' => 'New Year celebration',
                'is_recurring' => true,
                'recurring_type' => 'Yearly',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Chinese New Year',
                'date' => '2024-02-10',
                'type' => 'Religious',
                'description' => 'Chinese New Year celebration',
                'is_recurring' => false,
                'recurring_type' => 'None',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Nyepi (Day of Silence)',
                'date' => '2024-03-11',
                'type' => 'Religious',
                'description' => 'Hindu Day of Silence',
                'is_recurring' => false,
                'recurring_type' => 'None',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Good Friday',
                'date' => '2024-03-29',
                'type' => 'Religious',
                'description' => 'Christian Good Friday',
                'is_recurring' => false,
                'recurring_type' => 'None',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Eid al-Fitr Day 1',
                'date' => '2024-04-10',
                'type' => 'Religious',
                'description' => 'End of Ramadan - Day 1',
                'is_recurring' => false,
                'recurring_type' => 'None',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Eid al-Fitr Day 2',
                'date' => '2024-04-11',
                'type' => 'Religious',
                'description' => 'End of Ramadan - Day 2',
                'is_recurring' => false,
                'recurring_type' => 'None',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Labor Day',
                'date' => '2024-05-01',
                'type' => 'National',
                'description' => 'International Workers\' Day',
                'is_recurring' => true,
                'recurring_type' => 'Yearly',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Vesak Day',
                'date' => '2024-05-23',
                'type' => 'Religious',
                'description' => 'Buddha\'s Birthday',
                'is_recurring' => false,
                'recurring_type' => 'None',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Ascension Day',
                'date' => '2024-05-09',
                'type' => 'Religious',
                'description' => 'Christian Ascension Day',
                'is_recurring' => false,
                'recurring_type' => 'None',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Pancasila Day',
                'date' => '2024-06-01',
                'type' => 'National',
                'description' => 'Pancasila Day',
                'is_recurring' => true,
                'recurring_type' => 'Yearly',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Eid al-Adha',
                'date' => '2024-06-17',
                'type' => 'Religious',
                'description' => 'Festival of Sacrifice',
                'is_recurring' => false,
                'recurring_type' => 'None',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Independence Day',
                'date' => '2024-08-17',
                'type' => 'National',
                'description' => 'Indonesian Independence Day',
                'is_recurring' => true,
                'recurring_type' => 'Yearly',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Islamic New Year',
                'date' => '2024-07-07',
                'type' => 'Religious',
                'description' => 'Islamic New Year 1446 H',
                'is_recurring' => false,
                'recurring_type' => 'None',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Prophet Muhammad\'s Birthday',
                'date' => '2024-09-16',
                'type' => 'Religious',
                'description' => 'Maulid Nabi Muhammad SAW',
                'is_recurring' => false,
                'recurring_type' => 'None',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Christmas Day',
                'date' => '2024-12-25',
                'type' => 'Religious',
                'description' => 'Christmas celebration',
                'is_recurring' => true,
                'recurring_type' => 'Yearly',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            
            // 2025 Holidays (recurring ones)
            [
                'name' => 'New Year\'s Day',
                'date' => '2025-01-01',
                'type' => 'National',
                'description' => 'New Year celebration',
                'is_recurring' => true,
                'recurring_type' => 'Yearly',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Labor Day',
                'date' => '2025-05-01',
                'type' => 'National',
                'description' => 'International Workers\' Day',
                'is_recurring' => true,
                'recurring_type' => 'Yearly',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Pancasila Day',
                'date' => '2025-06-01',
                'type' => 'National',
                'description' => 'Pancasila Day',
                'is_recurring' => true,
                'recurring_type' => 'Yearly',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Independence Day',
                'date' => '2025-08-17',
                'type' => 'National',
                'description' => 'Indonesian Independence Day',
                'is_recurring' => true,
                'recurring_type' => 'Yearly',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'name' => 'Christmas Day',
                'date' => '2025-12-25',
                'type' => 'Religious',
                'description' => 'Christmas celebration',
                'is_recurring' => true,
                'recurring_type' => 'Yearly',
                'is_active' => true,
                'delete_flag' => false,
                'created_at' => now(),
                'updated_at' => now()
            ]
        ]);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('m_holidays');
    }
};