<?php

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

/**
 * Tax fields on invoices. Populated from provider webhook payloads —
 * Stripe Tax `total_tax_amounts[]`, Razorpay GST `tax_amount`, PayPal
 * plan-level `taxes` percentage. The merchant configures tax in each
 * provider's dashboard; we only persist what they tell us so /account
 * /subscription and /admin/invoices/{id} can surface the breakdown.
 *
 * Defaults are zero / null so historic invoices keep rendering unchanged
 * — the UI hides the breakdown when `tax_cents = 0`.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->unsignedBigInteger('tax_cents')->default(0)->after('amount_cents');
            $table->unsignedInteger('tax_rate_bps')->nullable()->after('tax_cents');
            $table->string('tax_label', 32)->nullable()->after('tax_rate_bps');
            $table->string('tax_country', 2)->nullable()->after('tax_label');
        });
    }

    public function down(): void
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->dropColumn(['tax_cents', 'tax_rate_bps', 'tax_label', 'tax_country']);
        });
    }
};
