<?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('fish_marine_grid_cache', function (Blueprint $table) {
            $table->id();
            $table->decimal('lat', 10, 7);
            $table->decimal('lon', 10, 7);
            $table->date('snapshot_date');
            $table->decimal('chlorophyll_mg_m3', 12, 6)->nullable();
            $table->decimal('current_speed_m_s', 10, 6)->nullable();
            $table->decimal('current_direction_deg', 9, 4)->nullable();
            $table->string('dataset_key', 96)->default('default');
            $table->timestamps();

            $table->unique(['lat', 'lon', 'snapshot_date', 'dataset_key'], 'fish_marine_grid_cache_unique_point_day');
            $table->index(['snapshot_date', 'dataset_key']);
        });
    }

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