package cn.iocoder.yudao.module.system.api.notify;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
import cn.iocoder.yudao.module.system.enums.notify.NotifyTemplateTypeConstants;
import cn.iocoder.yudao.module.system.service.notify.NotifySendService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 站内信发送 API 实现类
 *
 * @author xrcoder
 */
@Service
public class NotifyMessageSendApiImpl implements NotifyMessageSendApi {

    @Resource
    private NotifySendService notifySendService;

    @Override
    public Long sendSingleMessageToAdmin(NotifySendSingleToUserReqDTO reqDTO) {
        return notifySendService.sendSingleNotifyToAdmin(reqDTO.getUserId(),
                reqDTO.getTemplateCode(), reqDTO.getTemplateParams());
    }

    @Override
    public Long sendSingleMessageToMember(NotifySendSingleToUserReqDTO reqDTO) {
        return notifySendService.sendSingleNotifyToMember(reqDTO.getUserId(),
                reqDTO.getTemplateCode(), reqDTO.getTemplateParams());
    }

    @Override
    public Long sendSingleMessageToMemberForOA(Long employeeId, String content) {
        if (employeeId == null || StrUtil.isBlank(content)) {
            return -1L;
        }
        // 使用定义好的模版
        String templateCode = NotifyTemplateTypeConstants.SYSTEM_MESSAGE;
        Map<String, Object> templateParams = new HashMap<>();
        templateParams.put("content", content);
        return notifySendService.sendSingleNotifyToMember(employeeId, templateCode, templateParams);
    }

}
