<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('api_requests', function (Blueprint $table) {
            $table->id();
            $table->foreignId('api_token_id')->constrained()->onDelete('cascade');
            $table->string('endpoint');
            $table->string('method', 10); // GET, POST, PUT, DELETE
            $table->string('ip_address', 45);
            $table->integer('response_status');
            $table->integer('response_time_ms')->nullable();
            $table->timestamp('created_at');

            $table->index(['api_token_id', 'created_at']);
            $table->index('endpoint');
            $table->index('created_at');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('api_requests');
    }
};
