<?php

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

/**
 * PRC-1143 — konsolide şema: `domain_sync_logs` tablosunun TAM tanımı (tek dosya).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('domain_sync_logs', function (Blueprint $t) {
            $t->id();
            $t->unsignedBigInteger('client_domain_id');
            $t->string('old_status', 255)->nullable();
            $t->string('new_status', 255)->nullable();
            $t->date('old_expire_date')->nullable();
            $t->date('new_expire_date')->nullable();
            $t->string('sync_source', 255)->default('cron');
            $t->boolean('status_changed')->default(0);
            $t->boolean('expiry_changed')->default(0);
            $t->boolean('client_notified')->default(0);
            $t->boolean('admin_notified')->default(0);
            $t->text('registrar_response')->nullable();
            $t->text('error')->nullable();
            $t->timestamp('created_at')->nullable();
            $t->timestamp('updated_at')->nullable();
            $t->index('client_domain_id', 'domain_sync_logs_client_domain_id_index');
            $t->index('created_at', 'domain_sync_logs_created_at_index');
            $t->index('status_changed', 'domain_sync_logs_status_changed_index');
            $t->foreign('client_domain_id', 'domain_sync_logs_client_domain_id_foreign')->references('id')->on('client_domains')->onDelete('cascade');
        });
    }

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