<?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('contract_reminder_logs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('contract_id');
            $table->unsignedBigInteger('client_id');
            $table->integer('days_before_cutoff')->nullable(); // null for new_version dispatches
            $table->string('kind', 32); // 'new_version' | 'grace_reminder'
            $table->timestamp('sent_at');
            $table->timestamps();

            $table->foreign('contract_id')->references('id')->on('contracts')->cascadeOnDelete();
            $table->foreign('client_id')->references('id')->on('clients')->cascadeOnDelete();
            $table->unique(['contract_id', 'client_id', 'kind', 'days_before_cutoff'], 'crl_dedupe_idx');
        });
    }
    public function down(): void
    {
        Schema::dropIfExists('contract_reminder_logs');
    }
};
