<?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_opinions', function (Blueprint $table) {
            $table->id();
            $table->string('opinion_number')->comment('شماره نظریه');
            $table->date('opinion_date')->nullable()->comment('تاریخ نظریه');
            $table->string('subject', 1000)->nullable()->comment('موضوع استعلام یا نظریه');
            $table->longText('full_text')->comment('متن کامل نظریه و استعلام');
            $table->string('issuing_authority')->nullable()->comment('مرجع صدور');
            $table->foreignId('category_id')->constrained('legal_opinion_categories')->onDelete('cascade')->comment('شناسه دسته‌بندی');
            $table->timestamps();

            $table->unique(['opinion_number', 'category_id'], 'unique_opinion_category');
        });
    }

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