<?php

declare(strict_types=1);

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('service_build_milestones', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('subscription_id')->constrained()->cascadeOnDelete();
            $table->string('stage', 32); // ordered | hardware_acquired | assembly | racked | deployed
            $table->timestamp('reached_at')->nullable();
            $table->text('note')->nullable();
            $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();

            $table->unique(['subscription_id', 'stage']);
            $table->index(['subscription_id', 'reached_at']);
        });
    }

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