<?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('site_health_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('website_id')->constrained('managed_sites')->cascadeOnDelete();
            $table->string('status');
            $table->string('health_status');
            $table->unsignedInteger('response_time_ms')->nullable();
            $table->string('message')->nullable();
            $table->json('payload')->nullable();
            $table->timestamp('checked_at');
            $table->timestamps();

            $table->index(['website_id', 'checked_at']);
        });
    }

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