package cn.iocoder.yudao.module.bpm.convert.message;

import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAWorkTaskDO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmConstants;
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.send.SmsSendSingleToUserReqDTO;
import cn.iocoder.yudao.framework.common.template.vo.MsgData;
import cn.iocoder.yudao.framework.common.template.vo.SubscribeMessageReqDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.Date;
import java.util.Map;

@Mapper
public interface BpmMessageConvert {

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

    @Mapping(target = "mobile", ignore = true)
    @Mapping(source = "userId", target = "userId")
    @Mapping(source = "templateCode", target = "templateCode")
    @Mapping(source = "templateParams", target = "templateParams")
    SmsSendSingleToUserReqDTO convert(Long userId, String templateCode, Map<String, Object> templateParams);

    @Mapping(source = "userId", target = "userId")
    @Mapping(source = "templateCode", target = "templateCode")
    @Mapping(source = "templateParams", target = "templateParams")
    NotifySendSingleToUserReqDTO convert1(Long userId, String templateCode, Map<String, Object> templateParams);




    /**
     * @param openId              微信小程序唯一id
     * @param processInstanceName 流程名称
     * @param startUserNickname   申请人
     * @param time                申请时间
     * @param schedule            流程进度
     * @param miniProgramState    小程序的状态
     * @return
     */
    default SubscribeMessageReqDTO convertProcessToDoReminder(String openId, String processInstanceName,
                                                              String startUserNickname, String time, String schedule, String processInstanceId, String miniProgramState) {
        SubscribeMessageReqDTO message = new SubscribeMessageReqDTO();
        message.setToUser(openId);
        message.setTemplateId("3cP4btlFSSiZk65qVewN_WoT_bh0OfUkYzzTsADOrR4");
        //待办标题
        MsgData processType = new MsgData();
        processType.setName("thing1");
        processType.setValue("您收到了一条新的待办任务:" + processInstanceName);
        message.addData(processType);

        //申请人
        MsgData applicant = new MsgData();
        applicant.setName("thing4");
        applicant.setValue(startUserNickname);
        message.addData(applicant);

        //申请时间
        MsgData createTime = new MsgData();
        createTime.setName("time5");
        createTime.setValue(time);
        message.addData(createTime);

        //当前进度
        MsgData currentSchedule = new MsgData();
        currentSchedule.setName("thing6");
        currentSchedule.setValue(schedule);
        message.addData(currentSchedule);

        message.setMiniProgramState(miniProgramState);
        message.setPage("subPagesB/bpm/task/todo/examineApprove?id=" + processInstanceId);
        return message;
    }

}
