package com.gic.haoban.manage.service.service.chat.impl;

import com.gic.api.base.commons.Page;
import com.gic.commons.util.PageHelperUtils;
import com.gic.haoban.manage.api.dto.chat.GroupChatActivityInviteLogDTO;
import com.gic.haoban.manage.api.qdto.chat.GroupChatActivityInviteLogQDTO;
import com.gic.haoban.manage.service.dao.mapper.chat.GroupChatActivityInviteLogMapper;
import com.gic.haoban.manage.service.entity.chat.TabGroupChatActivityInviteLog;
import com.gic.haoban.manage.service.service.chat.GroupChatActivityInviteLogService;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 社群邀请有礼邀请日志表(TabHaobanGroupChatActivityInviteLog)表服务实现类
 *
 * @author makejava
 * @since 2024-09-27 16:09:56
 */
@Service("groupChatActivityInviteLogService")
public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityInviteLogService {
    @Resource
    private GroupChatActivityInviteLogMapper groupChatActivityInviteLogMapper;

    private GroupChatActivityInviteLogDTO convertToDTO(TabGroupChatActivityInviteLog tabGroupChatActivityInviteLog){
        GroupChatActivityInviteLogDTO groupChatActivityInviteLogDTO = new GroupChatActivityInviteLogDTO();
        BeanUtils.copyProperties(tabGroupChatActivityInviteLog,groupChatActivityInviteLogDTO);
        return groupChatActivityInviteLogDTO;
    }

    @Override
    public List<GroupChatActivityInviteLogDTO> queryMaxBatchInviteLog(GroupChatActivityInviteLogQDTO inviteLogQDTO) {
        Integer maxBatch = groupChatActivityInviteLogMapper.queryMaxBatchByChatActivityIdAndInviterMemberId(inviteLogQDTO.getChatActivityId(), inviteLogQDTO.getInviterMemberId());
        //没有最大批次数据表示没有任何邀请数据 直接返回
        if (Objects.isNull(maxBatch)) {
            return Lists.newArrayList();
        }
        List<TabGroupChatActivityInviteLog> logList = groupChatActivityInviteLogMapper.queryList(inviteLogQDTO);
        if(CollectionUtils.isEmpty(logList)){
            return Lists.newArrayList();
        }
        return logList.stream().map(this::convertToDTO).collect(Collectors.toList());
    }

    @Override
    public Page<GroupChatActivityInviteLogDTO> queryInviteLogDetails(GroupChatActivityInviteLogQDTO inviteLogQDTO) {
        PageHelper.startPage(inviteLogQDTO);
        List<TabGroupChatActivityInviteLog> logList = groupChatActivityInviteLogMapper.queryList(inviteLogQDTO);
        return PageHelperUtils.changePageHelperToCurrentPage(logList, GroupChatActivityInviteLogDTO.class);
    }
}
