<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Enums\BudgetStatusType;

return new class extends Migration {
  /**
   * Run the migrations.
   */
  public function up(): void
  {
    Schema::create('budget_details', function (Blueprint $table) {
      $table->id();
      $table->foreignId('user_id')->constrained('users');
      $table->foreignId('user_review_id')->nullable()->constrained('users');
      $table->foreignId('budget_id')->constrained('budgets');
      $table->foreignId('budget_category_id')->nullable()->constrained('budget_categories')->onDelete('cascade');
      $table->string('code')->nullable()->index();
      $table->string('name');
      $table->text('description')->nullable();
      $table->bigInteger('price');
      $table->bigInteger('price_total');
      $table->string('status')->default(BudgetStatusType::Draft)->index();
      $table->text('status_message')->nullable();
      $table->timestamp('review_at')->nullable();
      $table->timestamps();
    });
  }

  /**
   * Reverse the migrations.
   */
  public function down(): void
  {
    Schema::dropIfExists('budget_details');
  }
};
