<?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('opening_balances', function (Blueprint $table) {
            $table->unsignedBigInteger('warehouse_id')->default(0)->after('entity_id');

            $table->dropUnique('opening_balances_entity_unique');
            $table->unique(
                ['company_id', 'entity_type', 'entity_id', 'warehouse_id'],
                'opening_balances_entity_unique'
            );
        });
    }

    public function down(): void
    {
        Schema::table('opening_balances', function (Blueprint $table) {
            $table->dropUnique('opening_balances_entity_unique');
            $table->dropColumn('warehouse_id');

            $table->unique(['company_id', 'entity_type', 'entity_id'], 'opening_balances_entity_unique');
        });
    }
};
