<?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->foreignId('company_id')->nullable()->constrained()->cascadeOnDelete();
            $table->string('name');
            $table->string('code')->nullable();
            $table->text('address')->nullable();
            $table->string('city')->nullable();
            $table->string('province');
            $table->decimal('latitude', 10, 8);
            $table->decimal('longitude', 11, 8);
            $table->integer('radius')->default(100); // dalam meter
            // headquarters = kantor pusat
            // branch = kantor cabang
            // bpkp = kantor BPKP Perwakilan (per provinsi)
            // pemda = kantor Pemda (per kota/kabupaten)
            $table->enum('type', ['headquarters', 'branch', 'bpkp', 'pemda'])->default('branch');
            $table->boolean('is_active')->default(true);
            $table->timestamps();

            $table->index(['province', 'type']);
            $table->index(['city', 'type']);
        });
    }

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