<?php

namespace App\Policies;

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

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

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