<?php

declare(strict_types=1);

namespace App\Policies\Concerns;

use App\Models\User;
use App\Services\BranchAccessService;

trait ChecksBranchAccess
{
    private function canAccessBranch(User $user, ?int $branchId): bool
    {
        $branchIds = app(BranchAccessService::class)->accessibleBranchIds($user);

        if ($branchIds === null) {
            return true;
        }

        return $branchId !== null && in_array($branchId, $branchIds, true);
    }
}
