package cn.iocoder.yudao.module.system.convert.worklog;

import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.module.system.api.subscribe.dto.MsgData;
import cn.iocoder.yudao.module.system.api.subscribe.dto.SubscribeMessageReqDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.comment.WorkLogCommentDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.Date;

@Mapper
public interface LogCommentConvert {

    LogCommentConvert INSTANCE = Mappers.getMapper(LogCommentConvert.class);

    /**
     * @param openId              微信小程序唯一id
     * @param logCommentDO        评论对象
     * @param nickname            发布人姓名
     * @param miniProgramState    小程序的状态
     * @return
     */
    default SubscribeMessageReqDTO convertLogComment(String openId, WorkLogCommentDO logCommentDO, String nickname, String miniProgramState) {

        SubscribeMessageReqDTO message = new SubscribeMessageReqDTO();
        message.setToUser(openId);
        message.setTemplateId("fH29xjNb8pe-7onQ-wE3QrBAC-y8aaC_oosYZKNMtzM");

        //消息类型
        MsgData noticeType = new MsgData();
        noticeType.setName("phrase8");
        if (logCommentDO.getType()) {
            noticeType.setValue("评论回复");
        }else {
            noticeType.setValue("日志评论");
        }
        message.addData(noticeType);

        //发送人
        MsgData publishMan = new MsgData();
        publishMan.setName("thing16");
        publishMan.setValue(nickname);
        message.addData(publishMan);

        //发送时间
        MsgData createTime = new MsgData();
        createTime.setName("time3");
        createTime.setValue(DateUtils.dateFormat(new Date(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
        message.addData(createTime);

        //消息内容
        MsgData content = new MsgData();
        String comment = logCommentDO.getComment();
        content.setName("thing2");
        if (comment.length() > 10) {
            comment = comment.substring(0,10) + ". . . . ";
        }
        content.setValue(comment);
        message.addData(content);

        message.setMiniprogramState(miniProgramState);
        message.setPage("/subPages/workLogDetail/workLogDetail?id=" + logCommentDO.getWorkLogId());
        return message;
    }
}
