<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::create('alert_logs', function (Blueprint $table) {
            $table->id();
            $table->string('alert_id')->unique();
            $table->string('employee_id');
            $table->text('message');
            $table->enum('type', ['urgent_log_reminder', 'general_alert', 'system_notification']);
            $table->enum('priority', ['low', 'medium', 'high']);
            $table->unsignedBigInteger('sent_by')->nullable();
            $table->timestamp('sent_at');
            $table->timestamp('acknowledged_at')->nullable();
            $table->enum('status', ['sent', 'delivered', 'acknowledged', 'failed'])->default('sent');
            $table->timestamps();

            $table->foreign('employee_id')->references('employee_id')->on('employees');
            $table->foreign('sent_by')->references('id')->on('users');
            $table->index(['employee_id', 'status']);
            $table->index('sent_at');
        });
    }

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