<?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('sites', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('code', 50)->unique()->comment('Código único identificador del sitio');
            $table->string('name', 150)->comment('Nombre del sitio');
            $table->decimal('latitude', 10, 7)->comment('Latitud geográfica del sitio');
            $table->decimal('longitude', 10, 7)->comment('Longitud geográfica del sitio');
            $table->string('maintenance_center', 150)->nullable()->comment('Centro de mantenimiento responsable');
            $table->string('type')->nullable()->comment('Tipo de sitio');
            $table->boolean('status')->default(true)->comment('Estado activo/inactivo del sitio');
            $table->foreignId('district_id')->comment('Distrito donde se ubica el sitio')->constrained('districts')->cascadeOnDelete();
            $table->foreignId('project_id')->nullable()->comment('Proyecto al que pertenece el sitio (opcional)')->constrained('projects')->restrictOnDelete();
            $table->timestamps();
        });
    }

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