<?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('locations', function (Blueprint $table) {
            $table->id();                                         // BIGINT PK
            $table->string('display_name');                       // “Home”, “Reading Terminal Market”
            $table->text('raw_address')->nullable();              // what the user originally typed
            $table->string('street')->nullable();
            $table->string('city')->nullable();
            $table->string('state', 64)->nullable();
            $table->string('postal', 32)->nullable();
            $table->string('country', 64)->nullable();
            $table->decimal('lat', 9, 6)->nullable();             // ±90.000000
            $table->decimal('lon', 9, 6)->nullable();             // ±180.000000
            $table->string('phone', 32)->nullable();
            $table->json('hours_json')->nullable();               // flexible opening-hours blob
            $table->timestamps();

            // optional composite for fast “near me” queries
            $table->index(['lat', 'lon'], 'idx_locations_lat_lon');
        });
    }

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