package com.cool.store.dao;

import com.cool.store.dto.partner.PartnerBlackListDTO;
import com.cool.store.dto.partner.PartnerLineInfoAndBaseInfoDTO;
import com.cool.store.dto.partner.StageCountDTO;
import com.cool.store.dto.partner.*;
import com.cool.store.entity.HyPartnerLineInfoDO;
import com.cool.store.mapper.HyPartnerLineInfoMapper;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author suzhuhong
 * @Date 2023/6/8 15:10
 * @Version 1.0
 */
@Repository
public class HyPartnerLineInfoDAO {


    @Resource
    HyPartnerLineInfoMapper hyPartnerLineInfoMapper;


    public int insertSelective(HyPartnerLineInfoDO hyPartnerLineInfoDO){
        return hyPartnerLineInfoMapper.insertSelective(hyPartnerLineInfoDO);
    }

    public int batchInsert(List<HyPartnerLineInfoDO> hyPartnerLineInfoDOS){
        if (CollectionUtils.isEmpty(hyPartnerLineInfoDOS)){
            return -1;
        }
        return hyPartnerLineInfoMapper.batchInsert(hyPartnerLineInfoDOS);
    }


    public int batchDeleted(List<Long> lineIdList){
        if (CollectionUtils.isEmpty(lineIdList)){
            return -1;
        }
        return hyPartnerLineInfoMapper.batchDeleted(lineIdList);
    }

    public HyPartnerLineInfoDO selectByPrimaryKeySelective(Long id){
        if (id==null){
            return null;
        }
        return hyPartnerLineInfoMapper.selectByPrimaryKeySelective(id);
    }

    public int updateByPrimaryKeySelective(HyPartnerLineInfoDO hyPartnerLineInfoDO){
        return hyPartnerLineInfoMapper.updateByPrimaryKeySelective(hyPartnerLineInfoDO);
    }

    public int updateByPrimaryKey(HyPartnerLineInfoDO record){
        return hyPartnerLineInfoMapper.updateByPrimaryKey(record);
    }


    public  List<AdvanceLineDTO> getAdventLineCount( String userId, String currentDate,String endDate){
        if (StringUtils.isEmpty(userId)){
            return new ArrayList<>();
        }
        return hyPartnerLineInfoMapper.getAdventLineCount(userId,currentDate,endDate);
    }

    public StageCountDTO selectStagePendingCount(String userId){
        if (StringUtils.isEmpty(userId)){
            return new StageCountDTO(0,0);
        }
        return hyPartnerLineInfoMapper.selectStagePendingCount(userId);
    }

    public StageCountDTO selectStageFollowCount(String userId){
        if (StringUtils.isEmpty(userId)){
            return new StageCountDTO(0,0,0);
        }
        return hyPartnerLineInfoMapper.selectStageFollowCount(userId);
    }


    public PartnerLineInfoAndBaseInfoDTO selectPartnerLineInfoAndBaseInfo(Long lineId){
        if (lineId==null){
            return null;
        }
        return hyPartnerLineInfoMapper.selectPartnerLineInfoAndBaseInfo(lineId);
    }

    public List<HyPartnerLineInfoDO> lastMonthCloseLine(String userId, String lastMonthTodayDate){
        if (userId==null){
            return new ArrayList<>();
        }
        return hyPartnerLineInfoMapper.lastMonthCloseLine(userId,lastMonthTodayDate);
    }

    public int updateInvestmentManager(String userId, List<Long> lineIdList){
        if (StringUtils.isEmpty(userId)||CollectionUtils.isEmpty(lineIdList)){
            return -1;
        }
        return hyPartnerLineInfoMapper.updateInvestmentManager(lineIdList,userId);
    }



    public List<HyPartnerLineInfoDO> getLineListByLineIds( List<Long> lineIdList){
        if (CollectionUtils.isEmpty(lineIdList)){
            return Lists.newArrayList();
        }
        return hyPartnerLineInfoMapper.getLineListByLineIds(lineIdList);
    }


    public List<PartnerBlackListDTO> getBlackList( String userNameKeyword,String phoneKeyword, String intentAreaName , Integer acceptAdjustType){
        return hyPartnerLineInfoMapper.getBlackList(userNameKeyword,phoneKeyword,intentAreaName,acceptAdjustType);
    }


    public Boolean joinAndRemoveBlack( Long lineId, Integer status, String joinReason, String removeReason){
        if (lineId==null){
            return Boolean.FALSE;
        }
        return hyPartnerLineInfoMapper.joinAndRemoveBlack(lineId,status,joinReason,removeReason);
    }

    public List<PublicSeaLineDTO> getPublicSeaLineList( String userNameKeyword, String phoneKeyword, String intentAreaName, Integer acceptAdjustType, String updateStartTime, String updateEndTime, List<String> userIdList){
        return  hyPartnerLineInfoMapper.getPublicSeaLineList(userNameKeyword,phoneKeyword,intentAreaName,acceptAdjustType,updateStartTime,updateEndTime,userIdList);
    }

    public List<PrivateSeaLineDTO> getPrivateSeaLineList(String keyword, String keywordType, String workflowStage, String workflowStatus, String deadlineStart, String deadlineEnd,
                                                        String intentAreaName, Integer acceptAdjustType, String storeKeyword, String storeKeywordType, List<String> userIdList,List<String> developmentManagerList){
        return  hyPartnerLineInfoMapper.getPrivateSeaLineList( keyword,  keywordType,  workflowStage,  workflowStatus,  deadlineStart,  deadlineEnd,
                intentAreaName,  acceptAdjustType,  storeKeyword,  storeKeywordType, userIdList,developmentManagerList);
    }


    public List<HyPartnerLineInfoDO> getPartnerLastLine(List<String> partnerIdList){
        if (CollectionUtils.isEmpty(partnerIdList)){
            return new ArrayList<>();
        }
        return hyPartnerLineInfoMapper.getPartnerLastLine(partnerIdList);
    }
    public HyPartnerLineInfoDO getByPartnerId(String partnerId){
        if (StringUtils.isEmpty(partnerId)){
            return null;
        }
        return hyPartnerLineInfoMapper.getByPartnerId(partnerId);
    }


    public List<LineCountDTO> getFollowCountList( List<String> partnerIdList){
        if (CollectionUtils.isEmpty(partnerIdList)){
            return new ArrayList<>();
        }
        return hyPartnerLineInfoMapper.getFollowCountList(partnerIdList);
    }

    public List<HyPartnerLineInfoDO> getHyPartnerLineInfoListByIds( List<Long> lineIds){
        if (CollectionUtils.isEmpty(lineIds)){
            return new ArrayList<>();
        }
        return hyPartnerLineInfoMapper.getHyPartnerLineInfoListByIds(lineIds);
    }

    /**
     * 查询根据历史
     * @param partnerId
     * @return
     */
    public  List<HyPartnerLineInfoDO> getLineFollowHistoryList(String partnerId){
        if (partnerId==null){
            return new ArrayList<>();
        }
        return hyPartnerLineInfoMapper.getLineFollowHistoryList(partnerId);
    }

}
