/**
 * @license
 * Copyright 2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Behavior } from "#behavior/Behavior.js";
import { DclCertificateService, DclConfig, DclOtaUpdateService, DclVendorInfoService } from "@matter/protocol";
class DclBehavior extends Behavior {
  static id = "dcl";
  get #services() {
    if (!this.internal.services) {
      this.internal.services = this.endpoint.env.asDependent();
    }
    return this.internal.services;
  }
  /** Get DclConfig for production DCL based on the current state. */
  get productionConfig() {
    return { url: this.state.productionUrl };
  }
  /** Get DclConfig for test DCL based on the current state. */
  get testConfig() {
    return { url: this.state.testUrl };
  }
  /**
   * Get DclConfig based on a production flag.
   * @param isProduction - true for production, false for test
   */
  configForProduction(isProduction) {
    return isProduction ? this.productionConfig : this.testConfig;
  }
  /** Get or create the DclCertificateService with the current configuration. */
  get certificateService() {
    if (!this.env.has(DclCertificateService)) {
      new DclCertificateService(this.env, {
        fetchTestCertificates: this.state.fetchTestCertificates,
        fetchGithubCertificates: this.state.fetchGithubCertificates,
        dclConfig: this.productionConfig,
        testDclConfig: this.state.fetchTestCertificates ? this.testConfig : void 0
      });
    }
    return this.#services.get(DclCertificateService);
  }
  /** Get or create the DclVendorInfoService with the current configuration. */
  get vendorInfoService() {
    if (!this.env.has(DclVendorInfoService)) {
      new DclVendorInfoService(this.env, {
        dclConfig: this.productionConfig
      });
    }
    return this.#services.get(DclVendorInfoService);
  }
  /** Get or create the DclOtaUpdateService with the current configuration. */
  get otaUpdateService() {
    if (!this.env.has(DclOtaUpdateService)) {
      new DclOtaUpdateService(this.env, {
        productionDclConfig: this.productionConfig,
        testDclConfig: this.testConfig
      });
    }
    return this.#services.get(DclOtaUpdateService);
  }
  async [Symbol.asyncDispose]() {
    await this.internal.services?.close();
    await super[Symbol.asyncDispose]?.();
  }
}
((DclBehavior2) => {
  class State {
    /**
     * Production DCL API endpoint URL.
     *
     * Swagger docs: https://zigbee-alliance.github.io/distributed-compliance-ledger/#/
     */
    productionUrl = DclConfig.production.url;
    /** Test/Development DCL API endpoint URL. */
    testUrl = DclConfig.test.url;
    /** Whether to fetch test certificates in addition to production ones. */
    fetchTestCertificates = false;
    /** Whether to fetch development certificates from GitHub (only when fetchTestCertificates is true). */
    fetchGithubCertificates = true;
  }
  DclBehavior2.State = State;
  class Internal {
    services;
  }
  DclBehavior2.Internal = Internal;
})(DclBehavior || (DclBehavior = {}));
export {
  DclBehavior
};
//# sourceMappingURL=DclBehavior.js.map
