package com.cool.store.dao;

import com.cool.store.entity.LinePayDO;
import com.cool.store.mapper.LinePayMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author wxp
 * @FileName: LinePayDAO
 * @Description:提交意向金
 * @date 2024-03-27 14:33
 */
@Slf4j
@Repository
public class LinePayDAO {

    @Resource
    private LinePayMapper linePayMapper;


    public LinePayDO getByLineIdAndPayTypeAndShopId(Long lineId,Integer payBusinessType,Long shopId) {
        LinePayDO linePayDO = linePayMapper.getByLineIdAndPayTypeAndShopId(lineId,payBusinessType,shopId);
        return linePayDO;
    }

    /**
     *
     * @param lineId
     * @param payBusinessType
     * @return
     */
    @Deprecated
    public LinePayDO getLinePayByLineIdAndPayType(Long lineId,Integer payBusinessType) {
        LinePayDO linePayDO = linePayMapper.getByLineIdAndPayTypeAndShopId(lineId,payBusinessType,null);
        return linePayDO;
    }

    public Long addLinePay(LinePayDO linePayDO){
        linePayMapper.insertSelective(linePayDO);
        return linePayDO.getId();
    }

    public Integer updateLinePay(LinePayDO linePayDO){
        if(Objects.isNull(linePayDO)){
            return 0;
        }
        return linePayMapper.updateByPrimaryKeySelective(linePayDO);
    }


    public Map<Long,LinePayDO> getLinePayByLineIds(List<Long> lineIds,Integer  payBusinessType) {
        if(CollectionUtils.isEmpty(lineIds)){
            return  new HashMap<>();
        }
        List<LinePayDO> linePayDO = linePayMapper.getLinePayByLineIds(lineIds,null,payBusinessType);
        return linePayDO.stream().collect(Collectors.toMap(LinePayDO::getLineId, linePayDO1 -> linePayDO1, (o, n) -> o));
    }

    public Map<Long,LinePayDO> getLinePayByShopIds(List<Long> shopIds,Integer  payBusinessType) {
        if(CollectionUtils.isEmpty(shopIds)){
            return  new HashMap<>();
        }
        List<LinePayDO> linePayDO = linePayMapper.getLinePayByLineIds(null,shopIds,payBusinessType);
        return linePayDO.stream().collect(Collectors.toMap(LinePayDO::getShopId, linePayDO1 -> linePayDO1, (o, n) -> o));
    }
    public List<LinePayDO>getFranchiseFeePayInfoByShopId(Long shopId){
        if (Objects.isNull(shopId)){
            return null;
        }
        List<LinePayDO> franchiseFeePayInfoByShopId = linePayMapper.getFranchiseFeePayInfoByShopId(shopId);
        if (CollectionUtils.isEmpty(franchiseFeePayInfoByShopId)){
            return new ArrayList<>();
        }
        return franchiseFeePayInfoByShopId;
    }

    public LinePayDO getById(Long id) {
        return linePayMapper.selectByPrimaryKey(id);
    }
    public Integer deleteById(Long id,String userId) {
        return linePayMapper.deleteById(id,userId);
    }
    //数据处理专用0604，查询加盟费阶段缴费信息
    public List<LinePayDO> getDateHandler() {
        return linePayMapper.getDateHandler();
    }
    //数据处理专用0604，处理paytime paypic
    public Integer dataUpdateLinePay(List<LinePayDO> linePayDOList) {
        if (CollectionUtils.isEmpty(linePayDOList)){
            return  null;
        }
        return linePayMapper.dataUpdateLinePay(linePayDOList);
    }

    public LinePayDO selectByPaymentReceiptCode(String paymentReceiptCode) {
        return linePayMapper.selectByPaymentReceiptCode(paymentReceiptCode);
    }
    public Integer updateXgjClaimStatus(List<Long> shopIds,Integer xgjClaimStatus,Integer payBusinessType){
        if (CollectionUtils.isEmpty(shopIds)){
            return  null;
        }
        return linePayMapper.updateXgjClaimStatus(shopIds,xgjClaimStatus,payBusinessType);
    }
    public Integer deleteByShopId(List<Long> shopIds){
        if (CollectionUtils.isEmpty(shopIds)){
            return null;
        }
        return linePayMapper.deleteByShopId(shopIds);
    }
}
