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 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));
    }
}
