<?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('procedures', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained()->restrictOnDelete();
            $table->string('name_en', 190);
            $table->string('name_ar', 190);
            $table->string('category', 32)->index();
            $table->string('code', 32)->nullable();
            $table->unsignedBigInteger('default_price')->default(0); // whole IQD
            $table->unsignedSmallInteger('default_duration_min')->default(30);
            // Chart condition written when a plan item using this procedure
            // is completed (NULL = no automatic chart entry).
            $table->string('default_condition', 32)->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
            $table->softDeletes();
            $table->index(['tenant_id', 'is_active']);
        });
    }

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