<?php

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

return new class extends Migration
{
    public function up()
    {
        if (!Schema::hasTable('cautions')) {
            Schema::create('cautions', function (Blueprint $table) {
                $table->id();
                $table->string('reference');
                $table->string('market_name');
                $table->decimal('amount', 15, 2);
                $table->enum('method', ['cash', 'check'])->default('cash');
                $table->foreignId('check_id')->nullable()->constrained('checks');
                $table->date('submission_date');
                $table->date('expiry_date');
                $table->date('notification_date')->nullable();
                $table->enum('status', ['active', 'returned', 'expired', 'lost'])->default('active');
                $table->text('notes')->nullable();
                $table->foreignId('user_id')->constrained('users');
                $table->timestamps();
            });
        }
    }

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