<?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::create('portal_brands', function (Blueprint $t) {
            $t->bigIncrements('id');

            // One brand row per business (clinic). Unique = a clinic has
            // exactly one PWA brand.
            $t->unsignedInteger('business_id')->unique();

            // Resolution keys: the PWA finds its brand by (1) custom_domain
            // exact match, (2) subdomain that equals slug, (3) path /app/{slug}.
            // Both unique across the table.
            $t->string('slug', 64)->unique();
            $t->string('custom_domain', 191)->nullable()->unique();

            // Branding payload — small surface kept under one row so the
            // PWA can fetch it in a single request before login.
            $t->string('name');
            $t->string('accent_hex', 9)->default('#0d9488');     // includes optional alpha
            $t->string('logo_url')->nullable();
            $t->string('contact_phone', 32)->nullable();
            $t->string('contact_email')->nullable();
            $t->string('address')->nullable();

            // Which login methods the clinic admin enabled.
            // ['otp','magic','password','staff']
            $t->json('login_methods')->nullable();

            $t->boolean('is_active')->default(true);
            $t->timestamps();
        });
    }

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