<?php

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

/**
 * Links vet catalogue items to ERP products so prices flow into POS:
 *   - vc_soap_options.product_id  (per lab test / physical exam)
 *   - vc_vaccine_types.product_id (per vaccine)
 *   - vc_doctors.product_id       (per doctor's visit/consultation fee)
 */
class AddProductIdToVcCatalogues extends Migration
{
    public function up()
    {
        Schema::table('vc_soap_options', function (Blueprint $table) {
            if (!Schema::hasColumn('vc_soap_options', 'product_id')) {
                $table->unsignedInteger('product_id')->nullable()->after('label')->index();
            }
        });

        Schema::table('vc_vaccine_types', function (Blueprint $table) {
            if (!Schema::hasColumn('vc_vaccine_types', 'product_id')) {
                $table->unsignedInteger('product_id')->nullable()->after('name')->index();
            }
        });

        Schema::table('vc_doctors', function (Blueprint $table) {
            if (!Schema::hasColumn('vc_doctors', 'product_id')) {
                $table->unsignedInteger('product_id')->nullable()->after('consultation_fee')->index();
            }
        });
    }

    public function down()
    {
        Schema::table('vc_soap_options', function (Blueprint $table) {
            if (Schema::hasColumn('vc_soap_options', 'product_id')) $table->dropColumn('product_id');
        });
        Schema::table('vc_vaccine_types', function (Blueprint $table) {
            if (Schema::hasColumn('vc_vaccine_types', 'product_id')) $table->dropColumn('product_id');
        });
        Schema::table('vc_doctors', function (Blueprint $table) {
            if (Schema::hasColumn('vc_doctors', 'product_id')) $table->dropColumn('product_id');
        });
    }
}
