/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */

import { Message } from "#codec/MessageCodec.js";
import type { Session } from "#session/Session.js";
import { MatterError, NoResponseTimeoutError } from "@matter/general";
import { Status, StatusResponseError } from "@matter/types";

/**
 * Indicates MRP retries were exhausted without a response from the client.
 *
 * @deprecated
 */
export class RetransmissionLimitReachedError extends NoResponseTimeoutError {}

/**
 * Thrown when we receive a message on an exchange that we did not expect.
 */
export class UnexpectedMessageError extends MatterError {
    public constructor(
        message: string,
        session: Session,
        public readonly receivedMessage: Message,
    ) {
        super(`(${Message.diagnosticsOf(session, receivedMessage)}) ${message}`);
    }
}

/**
 * Thrown for communication attempts on closed sessions.
 */
export class SessionClosedError extends MatterError {}

/**
 * Thrown for operations that are illegal because a session is not associated with a fabric.
 */
export class NoAssociatedFabricError extends StatusResponseError {
    constructor(message: string) {
        super(message, Status.UnsupportedAccess);
    }
}
