package com.sjyt.icom.asst.common.model.message;

import com.sjyt.icom.asst.common.enums.ErrorCodeEnum;
import com.sjyt.icom.asst.common.enums.MsgTypeEnum;
import com.sjyt.icom.asst.common.model.sdp.RespError;

import java.util.Map;

/**
 * <p>NewsHelper</p>
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/7/1 16:31
 */
public class NewsHelper {
    public static News news(NewCommon newCommon) {
        final Message message = Message.builder().cmd(newCommon.getCmd()).build();
        return News.builder().from(newCommon.getFrom()).to(newCommon.getTo()).message(message).build();
    }

    public static News news(NewCommon newCommon, Map<String, Object> body) {
        final News news = news(newCommon);
        news.getMessage().setBody(body);
        return news;
    }
    public static RespError Error(String code, String errorText) {
        return RespError.builder().code(code).msg(errorText).msgType(MsgTypeEnum.RespError.getCODE()).build();
    }
    public static RespError Error(ErrorCodeEnum codeEnum) {
        return RespError.builder().code(codeEnum.CODE).msg(codeEnum.VALUE).msgType(MsgTypeEnum.RespError.CODE).build();
    }
}
