package com.njcn.rdms.module.system.api.notify;

import com.njcn.rdms.framework.common.enums.UserTypeEnum;
import com.njcn.rdms.framework.common.pojo.CommonResult;
import com.njcn.rdms.framework.common.util.object.BeanUtils;
import com.njcn.rdms.module.system.api.notify.dto.NotifySingleSendReqDTO;
import com.njcn.rdms.module.system.api.notify.dto.NotifyUnreadMessageListReqDTO;
import com.njcn.rdms.module.system.api.notify.dto.NotifyUnreadMessageRespDTO;
import com.njcn.rdms.module.system.dal.dataobject.notify.NotifyMessageDO;
import com.njcn.rdms.module.system.service.notify.NotifyMessageService;
import com.njcn.rdms.module.system.service.notify.NotifySendService;
import io.swagger.v3.oas.annotations.Hidden;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.njcn.rdms.framework.common.pojo.CommonResult.success;

/**
 * {@link NotifyMessageSendApi} 的实现：委托现有 {@link NotifySendService}，不重写发送逻辑。
 * 未读查询同理委托 {@link NotifyMessageService}，userType 固定 ADMIN（与发送口径一致）。
 *
 * @author hongawen
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
@Hidden
public class NotifyMessageSendApiImpl implements NotifyMessageSendApi {

    @Resource
    private NotifySendService notifySendService;
    @Resource
    private NotifyMessageService notifyMessageService;

    @Override
    public CommonResult<Long> sendSingleNotify(NotifySingleSendReqDTO reqDTO) {
        Long logId = notifySendService.sendSingleNotify(reqDTO.getUserId(), UserTypeEnum.ADMIN.getValue(),
                reqDTO.getTemplateCode(), reqDTO.getTemplateParams(), reqDTO.getLevel());
        return success(logId);
    }

    @Override
    public CommonResult<List<NotifyUnreadMessageRespDTO>> getUnreadNotifyMessageListByTemplateCodes(
            NotifyUnreadMessageListReqDTO reqDTO) {
        List<NotifyMessageDO> list = notifyMessageService.getUnreadNotifyMessageListByTemplateCodes(
                reqDTO.getUserIds(), UserTypeEnum.ADMIN.getValue(), reqDTO.getTemplateCodes());
        return success(BeanUtils.toBean(list, NotifyUnreadMessageRespDTO.class));
    }

}
