<?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('domains', function (Blueprint $table) {
            $table->id();
            $table->foreignId('workspace_id')->constrained()->cascadeOnDelete();
            $table->string('hostname', 253)->unique();
            $table->enum('type', ['short', 'bio', 'both'])->default('short');
            $table->timestamp('verified_at')->nullable();
            $table->string('verification_token', 64)->nullable();
            $table->enum('ssl_status', ['pending', 'active', 'failed'])->default('pending');
            $table->timestamp('ssl_issued_at')->nullable();
            $table->timestamp('ssl_expires_at')->nullable();
            $table->boolean('is_default')->default(false);
            $table->timestamps();
            $table->index(['workspace_id', 'hostname']);
        });
    }

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