<?php
// database/migrations/2024_01_01_000012_add_status_and_category_id_to_expenses_table.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::table('expenses', function (Blueprint $table) {
            // Check if columns don't exist before adding
            if (!Schema::hasColumn('expenses', 'status')) {
                $table->string('status')->default('approved')->after('payment_method');
            }
            if (!Schema::hasColumn('expenses', 'category_id')) {
                $table->foreignId('category_id')->nullable()->after('amount')->constrained('expense_categories')->onDelete('set null');
            }
            if (!Schema::hasColumn('expenses', 'receipt')) {
                $table->string('receipt')->nullable()->after('description');
            }
        });
    }

    public function down()
    {
        Schema::table('expenses', function (Blueprint $table) {
            $table->dropColumn(['status', 'category_id', 'receipt']);
        });
    }
};