/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Diagnostic } from "../log/Diagnostic.js";
import { MatterError } from "../MatterError.js";
import { repackErrorAs } from "../util/Error.js";
class NetworkError extends MatterError {
  get [Diagnostic.value]() {
    const { cause } = this;
    const causeMessage = cause instanceof Error ? cause.message : void 0;
    return Diagnostic.errorMessage({
      id: this.id,
      message: this.message,
      cause: causeMessage === this.message ? void 0 : cause
    });
  }
}
class TcpDisconnectError extends NetworkError {
}
class NoAddressAvailableError extends NetworkError {
}
class BindError extends NetworkError {
}
class AddressInUseError extends BindError {
}
class AddressUnreachableError extends NetworkError {
}
class NetworkUnreachableError extends NetworkError {
}
function tcpErrorFrom(error) {
  const code = error.code;
  switch (code) {
    case "ECONNRESET":
    case "EPIPE":
    case "ECONNABORTED":
    case "ETIMEDOUT":
      return repackErrorAs(error, TcpDisconnectError);
    case "EADDRINUSE":
      return repackErrorAs(error, AddressInUseError);
    case "EHOSTUNREACH":
      return repackErrorAs(error, AddressUnreachableError);
    case "ENETUNREACH":
      return repackErrorAs(error, NetworkUnreachableError);
    default:
      return repackErrorAs(error, NetworkError);
  }
}
const STANDARD_MATTER_PORT = 5540;
var InterfaceType = /* @__PURE__ */ ((InterfaceType2) => {
  InterfaceType2[InterfaceType2["Unspecified"] = 0] = "Unspecified";
  InterfaceType2[InterfaceType2["WiFi"] = 1] = "WiFi";
  InterfaceType2[InterfaceType2["Ethernet"] = 2] = "Ethernet";
  InterfaceType2[InterfaceType2["Cellular"] = 3] = "Cellular";
  InterfaceType2[InterfaceType2["Thread"] = 4] = "Thread";
  return InterfaceType2;
})(InterfaceType || {});
class Network {
  /** Create a TCP server socket. Override in platform implementations that support TCP. */
  createTcpListener(_options) {
    throw new NetworkError("TCP server not supported on this platform");
  }
  /** Connect to a remote TCP endpoint. Override in platform implementations that support TCP. */
  connectTcp(_host, _port, _options) {
    throw new NetworkError("TCP client not supported on this platform");
  }
  async close() {
  }
}
export {
  AddressInUseError,
  AddressUnreachableError,
  BindError,
  InterfaceType,
  Network,
  NetworkError,
  NetworkUnreachableError,
  NoAddressAvailableError,
  STANDARD_MATTER_PORT,
  TcpDisconnectError,
  tcpErrorFrom
};
//# sourceMappingURL=Network.js.map
