<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Point-in-time snapshots of stock/backlog dashboard metrics, captured daily
     * (5pm) so the dashboard can show whether those backlogs are trending down.
     * One row per (solicitor, day, metric). Solicitor-scoped because the capture
     * command runs in the console, where the BelongsToSolicitor global scope is
     * disabled — each solicitor's figures are computed and stored separately.
     */
    public function up(): void
    {
        Schema::create('daily_metric_snapshots', function (Blueprint $table) {
            $table->id();
            $table->foreignId('solicitor_id')->nullable()->index();
            $table->date('captured_on');
            $table->string('metric', 64);
            $table->unsignedInteger('value')->default(0);
            $table->timestamps();

            $table->unique(['solicitor_id', 'captured_on', 'metric']);
        });
    }

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