<?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('financial_statements', function (Blueprint $table) {
            $table->id();
            $table->string('statement_no')->unique();
            $table->enum('statement_type', ['balance_sheet', 'income_statement', 'cash_flow', 'trial_balance']);
            $table->date('from_date');
            $table->date('to_date');
            $table->json('data');
            $table->decimal('total_assets', 15, 2)->default(0);
            $table->decimal('total_liabilities', 15, 2)->default(0);
            $table->decimal('total_equity', 15, 2)->default(0);
            $table->decimal('total_revenue', 15, 2)->default(0);
            $table->decimal('total_expense', 15, 2)->default(0);
            $table->decimal('net_income', 15, 2)->default(0);
            $table->boolean('is_finalized')->default(false);
            $table->dateTime('finalized_at')->nullable();
            $table->foreignId('prepared_by')->constrained('users');
            $table->foreignId('approved_by')->nullable()->constrained('users');
            $table->text('notes')->nullable();
            $table->timestamps();
            
            $table->index('statement_type');
            $table->index(['from_date', 'to_date']);
            $table->index('is_finalized');
        });
    }

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