import { type ServerResponse } from '../common';
import { MethodNotImplementedError } from '../errors/transport.errors';
import { type AuthenticatedServerRequest } from '../server/server.types';
import { type TransportBus, type Transporter, type TransportKey, type TransportType } from './transport.types';

export class RemoteTransporter implements Transporter {
  readonly type: TransportType;
  readonly tokenHash: string;
  readonly sessionId: string;

  constructor(
    private readonly key: TransportKey,
    private readonly bus: TransportBus,
  ) {
    this.type = key.type;
    this.tokenHash = key.tokenHash;
    this.sessionId = key.sessionId;
  }
  ping(timeoutMs?: number): Promise<boolean> {
    throw new MethodNotImplementedError('RemoteTransporter', 'ping');
  }

  initialize(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void> {
    throw new MethodNotImplementedError('RemoteTransporter', 'initialize');
  }

  async handleRequest(_req: AuthenticatedServerRequest, _res: ServerResponse): Promise<void> {
    throw new MethodNotImplementedError('RemoteTransporter', 'handleRequest');
  }

  async destroy(_reason?: string): Promise<void> {
    throw new MethodNotImplementedError('RemoteTransporter', 'destroy');
  }

  get isInitialized(): boolean {
    return false;
  }

  markAsInitialized(): void {
    // No-op for remote transporters - initialization state is managed on the remote node
  }

  resetForReinitialization(): void {
    // No-op for remote transporters - initialization state is managed on the remote node
  }

  reregisterServer(): void {
    // No-op for remote transporters - server registration is managed on the remote node
  }
}
