<?php

declare(strict_types=1);

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('profiles', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->unique()->constrained()->cascadeOnDelete();

            $table->string('display_name')->nullable();
            $table->string('avatar_path')->nullable();
            $table->text('bio')->nullable();
            $table->string('country_code', 2)->nullable();
            $table->string('city')->nullable();
            $table->string('address_line1')->nullable();
            $table->string('address_line2')->nullable();
            $table->string('postal_code', 32)->nullable();
            $table->string('website_url')->nullable();
            $table->string('company_name')->nullable();
            $table->string('tax_id', 64)->nullable();

            /*
             * Channel preferences only -- which events a user cares about and
             * over which transport. No marketplace relationship is stored here.
             */
            $table->json('notification_preferences')->nullable();
            $table->string('whatsapp_number', 32)->nullable();
            $table->boolean('marketing_opt_in')->default(false);

            $table->timestamps();

            $table->index('country_code');
        });
    }

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