<?php

namespace App\Models;

class ChequeBook extends BaseModel
{
    protected $fillable = [
        'company_id',
        'account_id',
        'bank',
        'branch',
        'short_account_no',
        'book_no',
        'leaf_start',
        'leaf_end',
        'total_leaves',
        'is_active',
    ];

    protected $casts = [
        'leaf_start' => 'integer',
        'leaf_end' => 'integer',
        'total_leaves' => 'integer',
        'is_active' => 'boolean',
    ];

    public function account()
    {
        return $this->belongsTo(Account::class);
    }

    public static function calculateTotalLeaves(int $leafStart, int $leafEnd): int
    {
        return max(0, $leafEnd - $leafStart + 1);
    }

    public function leafRangeLabel(): string
    {
        return $this->leaf_start . ' – ' . $this->leaf_end;
    }
}
