<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // Update any existing 'regular' values to 'office'
        DB::table('attendances')
            ->where('type', 'regular')
            ->update(['type' => 'office']);

        // Modify the enum column to use 'office' instead of 'regular'
        DB::statement("ALTER TABLE `attendances` MODIFY COLUMN `type` ENUM('office', 'wfh', 'business_trip') NOT NULL DEFAULT 'office'");
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Update any existing 'office' values back to 'regular'
        DB::table('attendances')
            ->where('type', 'office')
            ->update(['type' => 'regular']);

        // Revert the enum column back to original values
        DB::statement("ALTER TABLE `attendances` MODIFY COLUMN `type` ENUM('regular', 'wfh', 'business_trip') NOT NULL DEFAULT 'regular'");
    }
};
