<?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('billing_accounts', function (Blueprint $table) {
            $table->id();

            // Basic billing account identity
            $table->string('name'); // e.g. "Smith Family" or "Acme Ltd"
            $table->string('contact_name')->nullable(); // attachment for companies

            // Primary parent user (nullable)
            $table->unsignedBigInteger('primary_parent_user_id')->nullable();
            $table->foreign('primary_parent_user_id')
                ->references('id')->on('users')
                ->nullOnDelete();

            // Core billing communication channel
            $table->string('invoice_email');

            // Optional phone for billing queries
            $table->string('phone')->nullable();

            // Address fields
            $table->string('address_line1');
            $table->string('address_line2')->nullable();
            $table->string('town');
            $table->string('postcode');
            $table->string('country');

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

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