<?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::create('cheque_books', function (Blueprint $table) {
            $table->id();
            $table->foreignId('company_id')->constrained()->cascadeOnDelete();
            $table->foreignId('account_id')->constrained()->cascadeOnDelete();
            $table->string('bank', 100);
            $table->string('branch', 100)->nullable();
            $table->string('short_account_no', 50)->nullable();
            $table->string('book_no', 50);
            $table->unsignedInteger('leaf_start');
            $table->unsignedInteger('leaf_end');
            $table->unsignedInteger('total_leaves');
            $table->boolean('is_active')->default(true);
            $table->timestamps();

            $table->unique(['company_id', 'account_id', 'book_no']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('cheque_books');
    }
};
