<?php

namespace App\Policies;

use App\Models\LoanDisbursement;
use App\Models\User;
use App\Services\BranchAccessService;
use App\Support\Authorization\PermissionName;

class LoanDisbursementPolicy
{
    public function __construct(private BranchAccessService $branchAccess)
    {
    }

    public function view(User $user, LoanDisbursement $disbursement): bool
    {
        return $user->can(PermissionName::LOANS_VIEW->value)
            && $this->branchAccess->canAccessBranch($user, (int) $disbursement->branch_id);
    }
}
