<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('offices', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('account_id');
            $table->string('name', 255);
            $table->string('address', 255);
            $table->string('postal_code', 45);
            $table->string('location', 255);
            $table->boolean('is_main_office');
            $table->string('email', 255);
            $table->string('phone', 20);
            $table->string('fax', 20)->nullable();
            $table->string('website_url', 255);
            $table->unsignedBigInteger('country_id')->nullable();
            $table->timestamps();

            $table->foreign('account_id')->references('id')
                ->on('accounts')->onDelete('CASCADE')->onUpdate('CASCADE');

            $table->foreign('country_id')->references('id')
                ->on('countries')->onDelete('SET NULL')->onUpdate('CASCADE');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('offices');
    }
};
