<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('companies', function (Blueprint $table) {
            if (! Schema::hasColumn('companies', 'logo_path')) {
                $table->string('logo_path')->nullable()->after('signature_image_path');
            }
            if (! Schema::hasColumn('companies', 'website')) {
                $table->string('website')->nullable()->after('email');
            }
            if (! Schema::hasColumn('companies', 'address_line1')) {
                $table->string('address_line1')->nullable()->after('address');
            }
            if (! Schema::hasColumn('companies', 'address_line2')) {
                $table->string('address_line2')->nullable()->after('address_line1');
            }
            if (! Schema::hasColumn('companies', 'contact_name')) {
                $table->string('contact_name')->nullable()->after('phone');
            }
            if (! Schema::hasColumn('companies', 'taxation_type')) {
                $table->string('taxation_type', 50)->nullable()->after('gstin');
            }
            if (! Schema::hasColumn('companies', 'service_tax_no')) {
                $table->string('service_tax_no', 50)->nullable()->after('taxation_type');
            }
            if (! Schema::hasColumn('companies', 'tax_inclusive_rates')) {
                $table->boolean('tax_inclusive_rates')->default(false)->after('service_tax_no');
            }
            if (! Schema::hasColumn('companies', 'bank_branch')) {
                $table->string('bank_branch')->nullable()->after('bank_name');
            }
            if (! Schema::hasColumn('companies', 'account_holder_name')) {
                $table->string('account_holder_name')->nullable()->after('bank_account');
            }
            if (! Schema::hasColumn('companies', 'bank_ad_code')) {
                $table->string('bank_ad_code', 50)->nullable()->after('bank_ifsc');
            }
            if (! Schema::hasColumn('companies', 'bank_swift')) {
                $table->string('bank_swift', 50)->nullable()->after('bank_ad_code');
            }
            if (! Schema::hasColumn('companies', 'bank_iban')) {
                $table->string('bank_iban', 50)->nullable()->after('bank_swift');
            }
            if (! Schema::hasColumn('companies', 'bank_sort_code')) {
                $table->string('bank_sort_code', 20)->nullable()->after('bank_iban');
            }
        });
    }

    public function down(): void
    {
        Schema::table('companies', function (Blueprint $table) {
            $table->dropColumn([
                'logo_path', 'website', 'address_line1', 'address_line2', 'contact_name',
                'taxation_type', 'service_tax_no', 'tax_inclusive_rates',
                'bank_branch', 'account_holder_name', 'bank_ad_code', 'bank_swift',
                'bank_iban', 'bank_sort_code',
            ]);
        });
    }
};
