<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateVcPetConditionsTable extends Migration
{
    public function up()
    {
        if (Schema::hasTable('vc_pet_conditions')) return;

        Schema::create('vc_pet_conditions', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('pet_id');
            $table->unsignedInteger('condition_id');
            $table->date('diagnosed_date')->nullable();
            $table->unsignedInteger('diagnosed_by')->nullable();
            $table->unsignedInteger('appointment_id')->nullable();
            $table->enum('severity', ['mild', 'moderate', 'severe'])->nullable();
            $table->enum('status', ['active', 'resolved', 'chronic'])->default('active');
            $table->text('notes')->nullable();
            $table->timestamps();

            $table->foreign('pet_id')->references('id')->on('vc_pets')->onDelete('cascade');
            $table->foreign('condition_id')->references('id')->on('vc_medical_conditions')->onDelete('cascade');
            $table->index('pet_id');
        });
    }

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