<?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('user_trust_links', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->foreignId('trust_service_id')->constrained()->onDelete('cascade');
            $table->enum('status', ['pending', 'challenge_sent', 'submitted', 'verified', 'failed'])->default('pending');
            $table->string('remote_id')->nullable();
            $table->string('remote_user_url')->nullable();
            $table->string('remote_proof_url')->nullable();
            $table->text('note')->nullable();
            $table->string('challenge_code', 12)->nullable();
            $table->timestamp('challenge_sent_at')->nullable();
            $table->timestamp('challenge_expires_at')->nullable();
            $table->timestamp('challenge_verified_at')->nullable();
            $table->foreignId('verified_by')->nullable()->constrained('users')->onDelete('set null');
            $table->timestamp('verified_at')->nullable();
            $table->timestamps();
            $table->unique(['user_id', 'trust_service_id']);
        });
    }

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