<?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('attendance_logs', function (Blueprint $table) {
            $table->id();
            $table->string('pin', 50);
            $table->dateTime('logged_at');
            $table->string('verified', 50)->nullable();
            $table->string('status', 50)->nullable();
            $table->string('device_ip', 45)->nullable();
            $table->json('raw')->nullable();
            $table->timestamps();

            $table->unique(['pin', 'logged_at', 'device_ip', 'status'], 'attendance_logs_unique');
            $table->index(['logged_at']);
            $table->index(['pin']);
        });
    }

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