package com.cool.store.dao;

import com.cool.store.entity.DecorationDesignInfoDO;
import com.cool.store.entity.DecorationMeasureDO;
import com.cool.store.mapper.DecorationMeasureMapper;
import com.cool.store.request.DeskRequest;
import com.cool.store.utils.StringUtil;
import com.cool.store.vo.desk.PreparationCommonPendingVO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

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

/**
 * @author ryan.xu
 * @date 2025/04/23
 */
@Repository
public class DecorationMeasureDAO {

    @Resource
    DecorationMeasureMapper decorationMeasureMapper;

    public DecorationMeasureDO getById(Long id) {
        if (id == null) {
            return null;
        }
        return decorationMeasureMapper.selectByPrimaryKey(id);
    }

    public List<DecorationMeasureDO> getByIds(List<Long> shopIds) {
        if (CollectionUtils.isEmpty(shopIds)) {
            return new ArrayList<>();
        }
        Example example = new Example(DecorationDesignInfoDO.class);
        example.createCriteria().andIn("shopId", shopIds);
        return decorationMeasureMapper.selectByExample(example);
    }

    public Integer insertSelective(DecorationMeasureDO decorationMeasureDO, String userId) {
        decorationMeasureDO.setCreateUserId(userId);
        decorationMeasureDO.setUpdateUserId(userId);
        decorationMeasureDO.setUpdateTime(new Date());
        decorationMeasureDO.setCreateTime(new Date());
        return decorationMeasureMapper.insertSelective(decorationMeasureDO);
    }
    public Integer insertSelective(DecorationMeasureDO decorationMeasureDO) {
        return decorationMeasureMapper.insertSelective(decorationMeasureDO);
    }

    public Integer updateByPrimaryKeySelective(DecorationMeasureDO decorationMeasureDO, String userId) {
        decorationMeasureDO.setUpdateUserId(userId);
        decorationMeasureDO.setUpdateTime(new Date());
        return decorationMeasureMapper.updateByPrimaryKeySelective(decorationMeasureDO);
    }
    public Integer updateByPrimaryKeySelective(DecorationMeasureDO decorationMeasureDO) {
        decorationMeasureDO.setUpdateTime(new Date());
        return decorationMeasureMapper.updateByPrimaryKeySelective(decorationMeasureDO);
    }

    public DecorationMeasureDO getByShopId(Long shopId) {
        if (shopId == null) {
            return null;
        }
        return decorationMeasureMapper.selectByShopId(shopId);
    }

    public List<PreparationCommonPendingVO> getByMeasureUserIdAndShopStage(String measureUserId, DeskRequest deskRequest){
        if (StringUtil.isBlank(measureUserId)){
            return null;
        }
        return decorationMeasureMapper.selectByMeasureUserIdAndShopStage(measureUserId,deskRequest);
    }
    //根据设计师和阶段900 查询 店铺id
    public List<PreparationCommonPendingVO> getShopIdListByDesignUserIdAndShopStage(String userId, DeskRequest deskRequest) {
        if (StringUtil.isBlank(userId)){
            return new ArrayList<>();
        }
        return decorationMeasureMapper.getShopIdListByDesignUserIdAndShopStage(userId,deskRequest);
    }


    //有 设计组长 和 设计师 查询 指定当前用户和  阶段为 900 待分配设计师 阶段为 901 设计中  设计表关联查询
    public List<PreparationCommonPendingVO> getShopIdListByDesignUserIdOrQuotationAndShopStage(String userId,DeskRequest deskRequest) {
        if (StringUtil.isBlank(userId)){
            return new ArrayList<>();
        }
        return decorationMeasureMapper.getShopIdListByDesignUserIdOrQuotationAndShopStage(userId,deskRequest);
    }
}
