<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     * 
     * Adds support for B2B vs B2C pricing:
     * - B2B: price_includes_tax = false (tax is a cost deduction)
     * - B2C: price_includes_tax = true (price shown includes VAT/IVA)
     */
    public function up(): void
    {
        Schema::table('business_settings', function (Blueprint $table) {
            // Whether the final price includes tax (B2C) or not (B2B)
            $table->boolean('price_includes_tax')->default(true)->after('tax_rate');
            
            // Tax rate for inclusion (IVA/VAT) - separate from deduction tax
            // This is the tax that gets ADDED to the price, not deducted from margin
            $table->decimal('vat_rate', 5, 2)->default(21.00)->after('price_includes_tax');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('business_settings', function (Blueprint $table) {
            $table->dropColumn(['price_includes_tax', 'vat_rate']);
        });
    }
};
