<?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('orders_header', function (Blueprint $table) {
            $table->foreignId('discount_id')->nullable()->constrained('master_discounts')->nullOnDelete()->after('bank_account_id');
            $table->string('discount_name')->nullable()->after('discount_id');
            $table->enum('discount_type', ['percent', 'fixed'])->nullable()->after('discount_name');
            $table->decimal('discount_value', 12, 2)->nullable()->after('discount_type');
            $table->decimal('discount_amount', 15, 2)->default(0)->after('discount_value');
            $table->decimal('grand_total_after_discount', 15, 2)->nullable()->after('discount_amount');
        });
    }

    public function down(): void
    {
        Schema::table('orders_header', function (Blueprint $table) {
            $table->dropConstrainedForeignId('discount_id');
            $table->dropColumn([
                'discount_name',
                'discount_type',
                'discount_value',
                'discount_amount',
                'grand_total_after_discount',
            ]);
        });
    }
};
