package com.sikey.wa04.business.application.service.message;

import com.sikey.wa04.business.domain.adapter.MessageCenterAdapter;
import com.sikey.wa04.business.domain.entity.MessageCenter;
import com.sikey.wa04.business.domain.entity.UserId;
import com.sikey.wa04.business.infrastructure.dto.model.ChildRefModel;
import com.sikey.wa04.business.infrastructure.repository.ChildRefRepository;
import com.sikey.wa04.common.interceptor.CurrentRequestUser;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class MessageCenterService {

    @Resource
    private MessageCenterAdapter messageCenterAdapter;

    @Resource
    private ChildRefRepository childRefRepository;

    /**
     * 查询消息
     *
     * @return
     */
    public List<MessageCenter> findMessageCenterByChild() {
        UserId userId = new UserId(CurrentRequestUser.get().getId());
        List<ChildRefModel> childRefModelList = childRefRepository.findByUserId(userId.getId());
        List<String> childList = childRefModelList.stream().map(ChildRefModel::getChildId).toList();
        return messageCenterAdapter.findMessageCenterByChild(childList);
    }

}
