<?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('franchise_zones', function (Blueprint $table) {
            $table->id();
            $table->foreignId('state_map_id')->constrained('state_maps')->cascadeOnDelete();
            $table->unsignedTinyInteger('zone_number');
            $table->string('zone_name');
            $table->decimal('boundary_start_lat', 10, 7);
            $table->decimal('boundary_start_lng', 10, 7);
            $table->decimal('boundary_end_lat', 10, 7);
            $table->decimal('boundary_end_lng', 10, 7);
            $table->decimal('center_lat', 10, 7);
            $table->decimal('center_lng', 10, 7);
            $table->decimal('radius_km', 8, 2)->default(75.00);
            $table->json('polygon_json')->nullable();
            $table->timestamps();

            $table->unique(['state_map_id', 'zone_number']);
        });
    }

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