<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('cash_categories', function (Blueprint $table) {
            $table->enum('type', ['pemasukan', 'pengeluaran'])->after('name')->default('pemasukan');
        });

        // Migrate existing data
        DB::table('cash_categories')->where('name', 'pengeluaran')->update(['type' => 'pengeluaran']);
        DB::table('cash_categories')->where('name', '!=', 'pengeluaran')->update(['type' => 'pemasukan']);
    }

    public function down(): void
    {
        Schema::table('cash_categories', function (Blueprint $table) {
            $table->dropColumn('type');
        });
    }
};
