package com.pcloud.book.pcloudkeyword.dao.impl;

import com.google.common.collect.Maps;

import com.pcloud.book.pcloudKeyword.dto.PcloudRobotDTO;
import com.pcloud.book.pcloudKeyword.dto.RobotClassifyDTO;
import com.pcloud.book.pcloudkeyword.dao.PcloudRobotDao;
import com.pcloud.book.pcloudkeyword.dto.PcloudRobotCountDTO;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobot;
import com.pcloud.book.pcloudkeyword.facade.response.PcloudRobotResponseVO;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component("pcloudRobotDao")
public class PcloudRobotDaoImpl extends BaseDaoImpl<PcloudRobot> implements PcloudRobotDao {

    @Override
    public void updateRealStatus(String wxId, Integer realStatus) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("realStatus", realStatus);
        map.put("wxId", wxId);
        this.getSqlSession().update("updateRealStatus", map);
    }

    @Override
    public PcloudRobot getByWxId(String wxId) {
        return super.getSqlSession().selectOne(getStatement("getByWxId"), wxId);
    }

    @Override
    public PcloudRobot getPcloudRobotByType(Integer robotType,Integer groupRobotType) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("robotType", robotType);
        map.put("groupRobotType", groupRobotType);
        return super.getSqlSession().selectOne(getStatement("getPcloudRobotByType"), map);
    }

    @Override
    public void updateWakeUpByClassifyIds(List<Integer> list) {
        this.getSessionTemplate().update(this.getStatement("updateWakeUpByClassifyIds"), list);
    }

    @Override
    public void clearWakeUp() {
        this.getSessionTemplate().update(this.getStatement("clearWakeUp"));
    }

    @Override
    public Map<String, RobotClassifyDTO> mapByIds4Classify(List<String> robotIds) {
        return this.getSessionTemplate().selectMap(this.getStatement("mapByIds4Classify"),robotIds,"wxId");
    }

    @Override
    public List<RobotClassifyDTO> getAllPcloudRobot() {
        return this.getSessionTemplate().selectList(this.getStatement("getAllPcloudRobot"));
    }

    @Override
    public List<RobotClassifyDTO> getAllPcloudRobotByType(Integer groupRobotType) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("groupRobotType", groupRobotType);
        return this.getSessionTemplate().selectList(this.getStatement("getAllPcloudRobotByType"),map);
    }

    @Override
    public PcloudRobot getByUniqueNumber(String uniqueNumber) {
        return this.getSessionTemplate().selectOne(this.getStatement("getByUniqueNumber"), uniqueNumber);
    }

    @Override
    public void updatePcloudRobotByWxId(PcloudRobot pcloudRobot) {
        this.getSessionTemplate().update(this.getStatement("updatePcloudRobotByWxId"), pcloudRobot);
    }

    @Override
    public List<String> getPcloudRobotByTypes(List<Integer> classifyIds) {
            return this.getSessionTemplate().selectList(this.getStatement("getPcloudRobotByTypes"), classifyIds);

    }

    @Override
    public void updateRobotState(Map<String, Object> map) {
        this.getSessionTemplate().update(this.getStatement("updateRobotState"), map);
    }

    @Override
    public List<RobotClassifyDTO> listSelfRobotByClassify(Map<String, Object> paramMap) {
        return this.getSessionTemplate().selectList(this.getStatement("listSelfRobotByClassify"), paramMap);
    }

    @Override
    public void updateRobotType(Map<String, Object> paramMap) {
        this.getSessionTemplate().update(this.getStatement("updateRobotType"), paramMap);
    }

    @Override
    public List<String> getPcloudRobotByClassify(Integer classifyId){
       return getSessionTemplate().selectList(getStatement("getPcloudRobotByClassify"), classifyId);
    }

    @Override
    public List<String> getPcloudRobotByRobotType(Integer classifyId, Integer groupRobotType) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("classifyId", classifyId);
        map.put("groupRobotType", groupRobotType);
        return getSessionTemplate().selectList(getStatement("getPcloudRobotByRobotType"), map);
    }

    @Override
    public List<PcloudRobotCountDTO> getPcloudRobotCount(List<Long> classifyIds) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("classifyIds", classifyIds);
        return getSessionTemplate().selectList(getStatement("getPcloudRobotCount"), map);
    }

    @Override
    public PcloudRobotResponseVO getSelfRobotClassify(String robotId) {
        return this.getSessionTemplate().selectOne(this.getStatement("getSelfRobotClassify"), robotId);
    }

    @Override
    public PcloudRobotDTO getValidPcloudRobotByType(Long robotType) {
        return this.getSessionTemplate().selectOne(this.getStatement("getValidPcloudRobotByType"), robotType);
    }

    @Override
    public Map<Long, PcloudRobotDTO> getValidPcloudRobotMapByType(List<Long> classifyIds) {
        return super.getSqlSession().selectMap(getStatement("getValidPcloudRobotMapByType"), classifyIds,"robotType");
    }
}
