<?php

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

class AddCurtainFeeFieldsToTailorsTable extends Migration
{
    public function up()
    {
        if (Schema::hasTable('tailors')) {
            Schema::table('tailors', function (Blueprint $table) {
                if (!Schema::hasColumn('tailors', 'fabric_meter_fee')) {
                    $table->decimal('fabric_meter_fee', 10, 2)->default(0)->after('tailor_fee');
                }
                if (!Schema::hasColumn('tailors', 'netting_meter_fee')) {
                    $table->decimal('netting_meter_fee', 10, 2)->default(0)->after('fabric_meter_fee');
                }
                if (!Schema::hasColumn('tailors', 'mattress_fee')) {
                    $table->decimal('mattress_fee', 10, 2)->default(0)->after('netting_meter_fee');
                }
                if (!Schema::hasColumn('tailors', 'pillow_fee')) {
                    $table->decimal('pillow_fee', 10, 2)->default(0)->after('mattress_fee');
                }
                if (!Schema::hasColumn('tailors', 'bolster_fee')) {
                    $table->decimal('bolster_fee', 10, 2)->default(0)->after('pillow_fee');
                }
            });
        }
    }

    public function down()
    {
        if (Schema::hasTable('tailors')) {
            foreach (['fabric_meter_fee', 'netting_meter_fee', 'mattress_fee', 'pillow_fee', 'bolster_fee'] as $column) {
                if (Schema::hasColumn('tailors', $column)) {
                    Schema::table('tailors', function (Blueprint $table) use ($column) {
                        $table->dropColumn($column);
                    });
                }
            }
        }
    }
}
