<?php

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

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

        Schema::create('vc_pets', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('business_id');
            $table->unsignedInteger('contact_id');
            $table->string('petname', 100);
            $table->string('species', 50)->nullable();
            $table->string('breed', 100)->nullable();
            $table->string('color', 50)->nullable();
            $table->enum('gender', ['male', 'female', 'unknown'])->default('unknown');
            $table->date('dob')->nullable();
            $table->decimal('weight_kg', 8, 2)->nullable();
            $table->string('bloodgroup', 20)->nullable();
            $table->string('microchip_no', 50)->nullable();
            $table->string('serial_no', 50)->nullable();
            $table->boolean('neutered')->default(false);
            $table->boolean('deceased')->default(false);
            $table->date('deceased_date')->nullable();
            $table->string('photo_path', 255)->nullable();
            $table->enum('status', ['active', 'inactive'])->default('active');
            $table->timestamps();

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

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