<?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('client_authorization_invitations', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('inviter_client_id');
            $table->string('invitee_email');
            $table->string('token')->unique();
            $table->json('permissions');
            $table->enum('status', ['pending', 'accepted', 'revoked', 'expired'])->default('pending');
            $table->timestamp('expires_at')->nullable();
            $table->timestamp('accepted_at')->nullable();
            $table->unsignedBigInteger('accepted_client_id')->nullable();
            $table->timestamps();

            // Indexes
            $table->index(['inviter_client_id']);
            $table->index(['invitee_email']);
            $table->index(['status']);
        });
    }

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