<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::create('budget_heads', function (Blueprint $table) {
            $table->id();
            $table->string('budget_code')->unique();
            $table->string('budget_name');
            $table->foreignId('account_id')->nullable()->constrained('chart_of_accounts');
            $table->enum('budget_type', ['revenue', 'expense', 'capital']);
            $table->year('fiscal_year');
            $table->decimal('budget_amount', 15, 2)->default(0);
            $table->decimal('actual_amount', 15, 2)->default(0);
            $table->decimal('balance', 15, 2)->default(0);
            $table->text('description')->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
            
            $table->index('fiscal_year');
            $table->index('budget_type');
            $table->index('account_id');
        });
    }

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