package com.cool.store.dao;

import com.cool.store.entity.ShopStageRemarkInfoDO;
import com.cool.store.enums.WorkflowSubStageStatusEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.mapper.ShopStageRemarkInfoMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Author: WangShuo
 * @Date: 2025/05/27/14:22
 * @Version 1.0
 * @注释:
 */
@Repository
public class ShopStageRemarkInfoDAO {
    @Autowired
    private ShopStageRemarkInfoMapper shopStageRemarkInfoMapper;

    public Integer insertOrUpdate(ShopStageRemarkInfoDO shopStageRemarkInfoDO) {
        if (shopStageRemarkInfoDO.getId() != null) {
            return shopStageRemarkInfoMapper.updateByPrimaryKeySelective(shopStageRemarkInfoDO);
        } else {
            return shopStageRemarkInfoMapper.insertSelective(shopStageRemarkInfoDO);
        }
    }
    public ShopStageRemarkInfoDO getByShopIdAndStage(Long shopId, Integer shopSubStageStatus) {
       if (Objects.isNull(shopId) || Objects.isNull(shopSubStageStatus)){
           return new ShopStageRemarkInfoDO();
       }
        Example example = new Example(ShopStageRemarkInfoDO.class);
         example.createCriteria().andEqualTo("shopId", shopId).andEqualTo("shopSubStageStatus", shopSubStageStatus);
        ShopStageRemarkInfoDO shopStageRemarkInfoDO = shopStageRemarkInfoMapper.selectOneByExample(example);
        if (Objects.isNull(shopStageRemarkInfoDO)){
            return new ShopStageRemarkInfoDO();
        }
        return shopStageRemarkInfoDO;
    }
    public ShopStageRemarkInfoDO getByLineIdAndStage(Long lineId, Integer workflowSubStageStatus) {
        if (Objects.isNull(lineId) || Objects.isNull(workflowSubStageStatus)){
            return new ShopStageRemarkInfoDO();
        }
        Example example = new Example(ShopStageRemarkInfoDO.class);
        example.createCriteria().andEqualTo("lineId", lineId).andEqualTo("workflowSubStageStatus", workflowSubStageStatus);
        ShopStageRemarkInfoDO shopStageRemarkInfoDO = shopStageRemarkInfoMapper.selectOneByExample(example);
        if (Objects.isNull(shopStageRemarkInfoDO)){
            return new ShopStageRemarkInfoDO();
        }
        return shopStageRemarkInfoDO;
    }

    public List<ShopStageRemarkInfoDO> getByShopIdsAndStage(List<Long> shopIds, List<Integer> shopSubStageStatusList) {
        if (CollectionUtils.isEmpty(shopIds) || CollectionUtils.isEmpty(shopSubStageStatusList)){
            return new ArrayList<>();
        }
        Example example = new Example(ShopStageRemarkInfoDO.class);
        example.createCriteria().andIn("shopId", shopIds).andIn("shopSubStageStatus", shopSubStageStatusList);
        List<ShopStageRemarkInfoDO> result = shopStageRemarkInfoMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(result)){
            return new ArrayList<>();
        }
        return result ;
    }

    public List<ShopStageRemarkInfoDO> getByShopIdsAndStages(List<Long> shopIds, List<Integer> shopSubStageList) {
        if (CollectionUtils.isEmpty(shopIds) || CollectionUtils.isEmpty(shopSubStageList)){
            return new ArrayList<>();
        }
        Example example = new Example(ShopStageRemarkInfoDO.class);
        example.createCriteria().andIn("shopId", shopIds).andIn("shopSubStage", shopSubStageList);
        List<ShopStageRemarkInfoDO> result = shopStageRemarkInfoMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(result)){
            return new ArrayList<>();
        }
        return result ;
    }

    public List<ShopStageRemarkInfoDO> getByLineIdsAndStage(List<Long> lineIds, List<Integer> workflowSubStageStatusList) {
        if (CollectionUtils.isEmpty(lineIds) || CollectionUtils.isEmpty(workflowSubStageStatusList)){
            return new ArrayList<>();
        }
        Example example = new Example(ShopStageRemarkInfoDO.class);
        example.createCriteria().andIn("lineId", lineIds).andIn("workflowSubStageStatus", workflowSubStageStatusList);
        List<ShopStageRemarkInfoDO> result = shopStageRemarkInfoMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(result)){
            return new ArrayList<>();
        }
        return result ;
    }
}
