<?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('station_prices_current', function (Blueprint $table): void {
            $table->string('station_id', 64);
            $table->string('fuel_type', 20);
            $table->unsignedSmallInteger('price_pence')->comment('Price in pence × 100, e.g. 15990 = 159.90p');
            $table->dateTime('price_effective_at')->comment('price_change_effective_timestamp from API');
            $table->dateTime('price_reported_at')->comment('price_last_updated from API');
            $table->dateTime('recorded_at')->comment('When this row was last upserted by us');

            $table->primary(['station_id', 'fuel_type']);
            $table->foreign('station_id')->references('node_id')->on('stations')->cascadeOnDelete();
        });
    }

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