<?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('sales_records', function (Blueprint $table) {
            $table->string('invoice_number', 30)->unique()->nullable()->after('id');
            $table->foreignId('sale_agent_id')->nullable()->constrained('users')->nullOnDelete()->after('customer_id');
            $table->text('billing_address')->nullable()->after('buyer_contact');
        });
    }

    public function down(): void
    {
        Schema::table('sales_records', function (Blueprint $table) {
            $table->dropForeign(['sale_agent_id']);
            $table->dropUnique(['invoice_number']);
            $table->dropColumn(['invoice_number', 'sale_agent_id', 'billing_address']);
        });
    }
};
