package com.cool.store.dao;

import com.cool.store.entity.PointAuditRecordDO;
import com.cool.store.entity.PointInfoDO;
import com.cool.store.entity.PointTodoInfoDO;
import com.cool.store.enums.NodeNoEnum;
import com.cool.store.mapper.PointTodoInfoMapper;
import com.cool.store.request.PointTodoPageRequest;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Repository;

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

@Repository
public class PointTodoInfoDAO {

    @Resource
    private PointTodoInfoMapper pointTodoInfoMapper;

    public Integer addPointTodoInfo(List<PointTodoInfoDO> todoList) {
        if(CollectionUtils.isEmpty(todoList)){
            return null;
        }
        return pointTodoInfoMapper.batchInsertSelective(todoList);
    }

    public List<String> getTodoUserList(Long pointId) {
        return pointTodoInfoMapper.getTodoUserList(pointId);
    }

    public List<PointTodoInfoDO> getTodoList(Long pointId) {
        return pointTodoInfoMapper.getTodoList(pointId);
    }

    public Integer updatePointTodoInfo(Long pointId, Integer nodeNo, Integer cycleCount, String handlerUserId) {
        return pointTodoInfoMapper.updatePointTodoInfo(pointId, nodeNo, cycleCount, handlerUserId);
    }

    public PointTodoInfoDO getPointToDoByUserIdAndPointId(String userId, Long pointId){
        if(StringUtils.isBlank(userId) || Objects.isNull(pointId)){
            return null;
        }
        return pointTodoInfoMapper.getPointToDoByUserIdAndPointId(userId, pointId);
    }

    public Page<PointInfoDO> getUserTodoList(PointTodoPageRequest request) {
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        return pointTodoInfoMapper.getUserTodoList(request);
    }

    public Integer getCurNodeNoByPoint(Long pointId){
        if(Objects.isNull(pointId)){
            return null;
        }
        return pointTodoInfoMapper.getCurNodeNoByPoint(pointId);
    }
}