<?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::table('purchases', function (Blueprint $table) {
            $table->foreignId('vendor_id')->nullable()->after('id')->constrained('vendors')->nullOnDelete();
            $table->foreignId('item_id')->nullable()->after('vendor_id')->constrained('items')->nullOnDelete();
            $table->string('item_category')->nullable()->after('item_id');
            $table->enum('payment_type', ['cash', 'due'])->default('cash')->after('cost');
        });
    }

    public function down(): void
    {
        Schema::table('purchases', function (Blueprint $table) {
            $table->dropConstrainedForeignId('vendor_id');
            $table->dropConstrainedForeignId('item_id');
            $table->dropColumn(['item_category', 'payment_type']);
        });
    }
};
