<?php

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

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

        Schema::create('vc_medical_reports', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('business_id');
            $table->unsignedInteger('appointment_id')->nullable();
            $table->unsignedInteger('pet_id');
            $table->unsignedInteger('contact_id');
            $table->unsignedInteger('doctor_id')->nullable();
            $table->enum('report_type', ['lab', 'xray', 'ultrasound', 'ecg', 'other'])->default('lab');
            $table->string('report_title', 200);
            $table->text('findings')->nullable();
            $table->json('attachments')->nullable();
            $table->timestamps();

            $table->foreign('business_id')->references('id')->on('business')->onDelete('cascade');
            $table->foreign('pet_id')->references('id')->on('vc_pets')->onDelete('cascade');
            $table->index(['business_id', 'pet_id']);
        });
    }

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