<?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('trade_documents', function (Blueprint $table) {
            $table->foreignId('account_id')->nullable()->index()->after('deal_id');
            $table->foreignId('contact_id')->nullable()->index()->after('account_id');
            $table->foreignId('salesperson_id')->nullable()->index()->after('created_by');
            $table->date('valid_until')->nullable()->after('due_date');
            $table->string('payment_terms')->nullable()->after('valid_until');
            $table->string('delivery_terms')->nullable()->after('payment_terms');
            $table->text('billing_address')->nullable()->after('delivery_terms');
            $table->text('delivery_address')->nullable()->after('billing_address');
            $table->decimal('other_charges', 15, 2)->default(0)->after('tax');
            $table->string('attachment_reference')->nullable()->after('notes');
        });
    }

    public function down(): void
    {
        Schema::table('trade_documents', function (Blueprint $table) {
            $table->dropColumn(['account_id','contact_id','salesperson_id','valid_until','payment_terms','delivery_terms','billing_address','delivery_address','other_charges','attachment_reference']);
        });
    }
};
