/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function ReadScope(read) {
  return {
    isRelevant(endpoint, cluster) {
      this.isRelevant = generateScopeTester(read, "any");
      return this.isRelevant(endpoint, cluster);
    },
    isWildcard(endpoint, cluster) {
      this.isWildcard = generateScopeTester(read, "all");
      return this.isWildcard(endpoint, cluster);
    },
    isFabricFiltered: read.isFabricFiltered ?? true
  };
}
function generateScopeTester(read, attrRequirement) {
  if (!read.attributeRequests?.length) {
    return isNever;
  }
  let wildcardEndpointClusters;
  let specificEndpointClusters;
  for (const { endpointId, clusterId, attributeId } of read.attributeRequests) {
    if (attributeId !== void 0 && attrRequirement === "all") {
      continue;
    }
    if (endpointId === void 0) {
      if (clusterId === void 0) {
        return isAlways;
      }
      (wildcardEndpointClusters ??= /* @__PURE__ */ new Set()).add(clusterId);
      continue;
    }
    if (clusterId === void 0) {
      (specificEndpointClusters ??= {})[endpointId] = true;
      continue;
    }
    if (attributeId === void 0) {
      let ep = specificEndpointClusters?.[endpointId];
      if (ep === true) {
        continue;
      }
      if (ep === void 0) {
        ep = (specificEndpointClusters ??= {})[endpointId] = /* @__PURE__ */ new Set();
      }
      ep.add(clusterId);
    }
  }
  return (endpoint, cluster) => {
    if (wildcardEndpointClusters?.has(cluster)) {
      return true;
    }
    const ep = specificEndpointClusters?.[endpoint];
    return ep === true || !!ep?.has(cluster);
  };
}
function isNever() {
  return false;
}
function isAlways() {
  return true;
}
export {
  ReadScope
};
//# sourceMappingURL=ReadScope.js.map
