import {
  ProtocolRequest,
  ProtocolResponse,
  ProtocolEncoder,
  ProtocolDecoder,
  ProtocolMessage,
  PacketBody,
  decodeProtocolMessage,
  ProtocolNotification
} from '@ucap-webmessenger/protocol';

// tslint:disable-next-line: no-empty-interface
export interface LogoutRequest extends ProtocolRequest {}

export interface LogoutResponse extends ProtocolResponse {
  reasonCode?: number;
}

export interface LogoutNotification extends ProtocolNotification {
  reasonCode?: number;
  ip?: string;
  mac?: string;
}

export const encodeLogout: ProtocolEncoder<LogoutRequest> = (
  req: LogoutRequest
) => {
  const bodyList: PacketBody[] = [];

  return bodyList;
};

export const decodeLogout: ProtocolDecoder<LogoutResponse> = (
  message: ProtocolMessage
) => {
  return decodeProtocolMessage(message, {
    reasonCode: Number(message.bodyList[0])
  } as LogoutResponse);
};

export const decodeLogoutNotification: ProtocolDecoder<LogoutNotification> = (
  message: ProtocolMessage
) => {
  return decodeProtocolMessage(message, {
    reasonCode: Number(message.bodyList[0]),
    ip: !!message.bodyList[1] ? message.bodyList[1] : '',
    mac: !!message.bodyList[2] ? message.bodyList[2] : ''
  } as LogoutNotification);
};
