<?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('policy_documents', function (Blueprint $table) {
            $table->id();
            $table->foreignId('association_id')->nullable()->constrained('associations')->cascadeOnDelete();
            $table->string('title');
            $table->string('slug');
            $table->string('type'); // privacy_policy, terms_of_service, disclaimer, etc.
            $table->longText('content');
            $table->string('version')->default('1.0.0');
            $table->boolean('is_active')->default(true);
            $table->foreignId('last_updated_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();

            $table->unique(['association_id', 'type']);
            $table->index(['type', 'is_active']);
        });
    }

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