<?php

namespace App\Policies;

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

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

    public function view(User $user, RemotePaymentSubmission $submission): bool
    {
        return $this->verify($user, $submission);
    }

    public function proof(User $user, RemotePaymentSubmission $submission): bool
    {
        return $this->verify($user, $submission);
    }

    public function verify(User $user, RemotePaymentSubmission $submission): bool
    {
        return $user->can(PermissionName::PAYMENTS_REMOTE_VERIFY->value)
            && $this->branchAccess->canAccessBranch($user, (int) $submission->branch_id);
    }
}
