"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ReadScope_exports = {};
__export(ReadScope_exports, {
  ReadScope: () => ReadScope
});
module.exports = __toCommonJS(ReadScope_exports);
/**
 * @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;
}
//# sourceMappingURL=ReadScope.js.map
