<?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('legal_documents', function (Blueprint $table) {
            $table->id();
            $table->string('table_name')->unique();
            $table->string('act_name');
            $table->enum('file_type', ['standard-xml', 'alternative-xml', 'pdf', 'html']);
            $table->string('file_path')->nullable();
            $table->unsignedBigInteger('law_subject_id');
            $table->unsignedBigInteger('jurisdiction_id');
            $table->json('act_type_ids');
            $table->string('language', 50)->default('english');
            $table->string('immigration_pathway')->nullable();
            $table->date('current_to_date')->nullable();
            $table->unsignedBigInteger('uploaded_by');
            $table->enum('status', ['active', 'inactive'])->default('active');
            $table->timestamps();

            $table->foreign('law_subject_id')->references('id')->on('law_subjects')->onDelete('cascade');
            $table->foreign('jurisdiction_id')->references('id')->on('jurisdictions')->onDelete('cascade');
            $table->foreign('uploaded_by')->references('id')->on('users')->onDelete('cascade');
            
            $table->index('status');
            $table->index('file_type');
            $table->index('law_subject_id');
            $table->index('jurisdiction_id');
        });
    }

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