package com.cool.store.dao;

import com.cool.store.dto.OperationLogDTO;
import com.cool.store.entity.OperationLogDO;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.mapper.OperationLogMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;

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

/**
 * @Author: WangShuo
 * @Date: 2024/08/28/下午5:01
 * @Version 1.0
 * @注释:
 */
@Repository
public class OperationLogDAO {
    @Resource
    private OperationLogMapper operationLogMapper;

    public Long addOperationLog(OperationLogDO operationLogDO) {
        if (Objects.isNull(operationLogDO)) {
            throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
        }
        operationLogDO.setCreateTime(new Date());
        operationLogMapper.insertSelective(operationLogDO);
        return operationLogDO.getId();
    }

    public Long batchAddOperationLog(List<OperationLogDO> operationLogDO) {
        if (CollectionUtils.isEmpty(operationLogDO)) {
            throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
        }
        return operationLogMapper.batchAddOperationLog(operationLogDO);
    }

    public Boolean batchUpdateByPrimaryKeySelective(List<OperationLogDO> operationLogs) {
        if (CollectionUtils.isEmpty(operationLogs)) {
            throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
        }
        for (OperationLogDO operationLog : operationLogs) {
            operationLogMapper.updateByPrimaryKeySelective(operationLog);
        }
        return Boolean.TRUE;
    }

    public OperationLogDO getBySubStageStatusEnumAndAuditIdNotNull(Long shopId, ShopSubStageStatusEnum shopSubStageStatusEnum,Integer type) {
        if (Objects.isNull(shopId) || Objects.isNull(shopSubStageStatusEnum)) {
            return null;
        }
        return operationLogMapper.getOrderByTime(shopId,shopSubStageStatusEnum.getShopSubStageStatus(),type);
    }
    public List<OperationLogDO> getBySubStageStatusEnumAndsStatus(Long shopId, ShopSubStageStatusEnum shopSubStageStatusEnum,Integer type) {
        if (Objects.isNull(shopId) || Objects.isNull(shopSubStageStatusEnum)) {
            return null;
        }
        return operationLogMapper.getBySubStageStatusEnumAndsStatus(shopId,shopSubStageStatusEnum.getShopSubStageStatus(),type);
    }

    public List<OperationLogDO> getBySubStageStatusAndUser(String userId,List<Integer> shopSubStageStatus) {
        if ( CollectionUtils.isEmpty(shopSubStageStatus)) {
            return null;
        }
        return operationLogMapper.getBySubStageStatusAndUser(userId,shopSubStageStatus);
    }
    public List<OperationLogDO> getByShopSubStage(Long shopId, List<Integer>  shopSubStageList, List<Integer> types) {
        if (Objects.isNull(shopId) || CollectionUtils.isEmpty(shopSubStageList)) {
            return null;
        }
        return operationLogMapper.getByShopSubStage(shopId,shopSubStageList,types);
    }

    public OperationLogDO getByCondition(Long shopId,Integer shopSubStageStatus) {
        if (Objects.isNull(shopId)) {
            return null;
        }
        return operationLogMapper.getByCondition(shopId,shopSubStageStatus);
    }

    public Integer updateByPrimaryKeySelective(OperationLogDO operationLogDO) {
        if (Objects.isNull(operationLogDO) ) {
            return null;
        }
        return operationLogMapper.updateByPrimaryKeySelective(operationLogDO);
    }

}
