<?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('domain_sync_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('client_domain_id')->constrained('client_domains')->cascadeOnDelete();
            $table->string('old_status')->nullable();
            $table->string('new_status')->nullable();
            $table->date('old_expire_date')->nullable();
            $table->date('new_expire_date')->nullable();
            $table->string('sync_source')->default('cron'); // cron, manual, admin
            $table->boolean('status_changed')->default(false);
            $table->boolean('expiry_changed')->default(false);
            $table->boolean('client_notified')->default(false);
            $table->boolean('admin_notified')->default(false);
            $table->text('registrar_response')->nullable();
            $table->text('error')->nullable();
            $table->timestamps();

            $table->index('client_domain_id');
            $table->index('status_changed');
            $table->index('created_at');
        });
    }

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