<?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('reminder_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('employee_id')->constrained('employees');
            $table->foreignId('employee_access_detail_id')->nullable()->constrained('employee_access_details');
            $table->foreignId('revocation_schedule_id')->nullable()->constrained('revocation_schedules');
            $table->enum('reminder_type', [
                'retirement_30', 'retirement_7', 'retirement_1', 'retirement_0',
                'access_revoke_7', 'access_revoke_1', 'access_revoke_0',
                'extended_reminder', 'extension_approved', 'extension_rejected'
            ]);
            $table->enum('channel', ['email', 'telegram', 'both']);
            $table->string('recipient_email', 100)->nullable();
            $table->string('recipient_telegram', 50)->nullable();
            $table->text('message_content');
            $table->enum('status', ['pending', 'sent', 'failed'])->default('pending');
            $table->timestamp('sent_at')->nullable();
            $table->text('error_message')->nullable();
            $table->timestamps();
            
            $table->index(['reminder_type', 'status']);
            $table->index(['employee_id', 'created_at']);
        });
    }

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