<?php

namespace App\Policies;

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

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

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