<?php

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

/**
 * Document numbers (entry_number, challan_number) are generated per-branch, so
 * their uniqueness must be scoped per-branch too — a global unique would make
 * two branches collide on the same sequence (e.g. JV-2026-00001).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('journal_entries', function (Blueprint $table) {
            $table->dropUnique(['entry_number']);
            $table->unique(['branch_id', 'entry_number']);
        });

        Schema::table('fee_challans', function (Blueprint $table) {
            $table->dropUnique(['challan_number']);
            $table->unique(['branch_id', 'challan_number']);
        });
    }

    public function down(): void
    {
        Schema::table('journal_entries', function (Blueprint $table) {
            $table->dropUnique(['branch_id', 'entry_number']);
            $table->unique('entry_number');
        });

        Schema::table('fee_challans', function (Blueprint $table) {
            $table->dropUnique(['branch_id', 'challan_number']);
            $table->unique('challan_number');
        });
    }
};
