package com.ruoyi.project.common.util;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.project.business.enums.MessageTypeEnum;
import com.ruoyi.project.common.domain.Message;
import com.ruoyi.project.common.service.ISseEmitterService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.context.MessageSource;

import java.util.List;

/**
 * @author : fangk
 * @date : 2024/7/3 15:08
 * @desc : 站内信工具类
 */
public class InternalMsgUtil {

    public static void sendMsg(List<Long> userIds, Object... args) {

        if (CollectionUtils.isNotEmpty(userIds)) {
            MessageSource source = SpringUtils.getBean(MessageSource.class);
            ISseEmitterService sseEmitterService = SpringUtils.getBean(ISseEmitterService.class);
            String msg = source.getMessage("project.message.awaitingReview", args, Constants.ZH_LOCALE);
            String msgUs = source.getMessage("project.message.awaitingReview", args, Constants.ES_LOCALE);
            String msgRu = source.getMessage("project.message.awaitingReview", args, Constants.RU_LOCALE);
            String msgEs = source.getMessage("project.message.awaitingReview", args, Constants.ES_LOCALE);
            Message message = new Message(MessageTypeEnum.PROJECT.getValue(), msg, msgUs, msgRu, msgEs);

            sseEmitterService.sendSaveMessage(userIds, message);
        }
    }
}
