<?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::create('expense_records', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('farm_id')->default(1);
            $table->date('expense_date');
            $table->enum('category', ['fingerlings', 'feed', 'drugs_chemicals', 'labour', 'electricity', 'maintenance', 'transport', 'other']);
            $table->string('description');
            $table->decimal('amount_naira', 15, 2);
            $table->foreignId('pond_id')->nullable()->constrained()->nullOnDelete();
            $table->foreignId('cycle_id')->nullable()->constrained('production_cycles')->nullOnDelete();
            $table->enum('payment_method', ['cash', 'bank_transfer', 'pos']);
            $table->string('receipt_photo')->nullable();
            $table->boolean('is_auto_generated')->default(false);
            $table->foreignId('logged_by')->constrained('users');
            $table->timestamps();
            $table->softDeletes();

            $table->index(['farm_id', 'expense_date']);
            $table->index(['pond_id', 'cycle_id']);
        });
    }

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