<?php

namespace App\Policies;

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

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

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