<?php

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

/**
 * One row per tenant, holding every landlord-editable configuration field
 * (Branding / Company / Invoice template / Locale — see the Settings tab on
 * the Master Control tenant detail page). Real typed columns rather than a
 * JSON blob, so each field is validated and queryable individually.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('tenant_settings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->unique()->constrained()->cascadeOnDelete();

            // Branding
            $table->string('branding_app_name')->nullable();
            $table->string('branding_logo_url')->nullable();
            $table->string('branding_login_heading')->nullable();
            $table->string('branding_login_subtitle')->nullable();

            // Company
            $table->string('company_name')->nullable();
            $table->string('company_registration_no')->nullable();
            $table->string('company_email')->nullable();
            $table->json('company_phone')->nullable();
            $table->text('company_address')->nullable();

            // Invoice template
            $table->string('invoice_bank')->nullable();
            $table->string('invoice_bank_name')->nullable();
            $table->string('invoice_bank_acc')->nullable();
            $table->string('invoice_footer_phone')->nullable();
            $table->string('invoice_footer_addr')->nullable();
            $table->text('invoice_note')->nullable();

            // Locale
            $table->string('locale_currency', 3)->nullable();
            $table->string('locale_currency_symbol', 10)->nullable();
            $table->string('locale_locale', 10)->nullable();
            $table->string('locale_timezone', 50)->nullable();

            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('tenant_settings');
    }
};
