import {
  APIRequest,
  MessageAPIResponse,
  APIJsonEncoder,
  APIDecoder
} from '@ucap-webmessenger/api';
import { DeviceType } from '@ucap-webmessenger/core';

export interface UnreadCountRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
}

export interface UnreadCountResponse extends MessageAPIResponse {
  unreadCount: number;
}

export const encodeUnreadCount: APIJsonEncoder<UnreadCountRequest> = (
  req: UnreadCountRequest
) => {
  return JSON.stringify(req);
};

export const decodeUnreadCount: APIDecoder<UnreadCountResponse> = (
  res: any
) => {
  return {
    responseCode: res.responseCode,
    responseMsg: res.responseMsg,
    unreadCount: res.unreadCount
  } as UnreadCountResponse;
};
