<?php

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

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

        Schema::create('vc_pet_owner_details', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('business_id');
            $table->unsignedInteger('contact_id')->unique();
            $table->string('emergency_contact_name', 100)->nullable();
            $table->string('emergency_contact_phone', 30)->nullable();
            $table->string('emergency_contact_relation', 50)->nullable();
            $table->string('occupation', 100)->nullable();
            $table->string('referred_by', 100)->nullable();
            $table->text('notes')->nullable();
            $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');
        });
    }

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