package com.njcn.rdms.module.project.dal.mysql.product;

import com.njcn.rdms.framework.mybatis.core.dataobject.BaseDO;
import com.njcn.rdms.framework.mybatis.core.mapper.BaseMapperX;
import com.njcn.rdms.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.njcn.rdms.module.project.dal.dataobject.product.ProductStatusLogDO;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ProductStatusLogMapper extends BaseMapperX<ProductStatusLogDO> {

    default List<ProductStatusLogDO> selectListByProductId(Long productId, String actionType, LocalDateTime[] operateTime) {
        return selectList(new LambdaQueryWrapperX<ProductStatusLogDO>()
                .eq(ProductStatusLogDO::getProductId, productId)
                .eqIfPresent(ProductStatusLogDO::getActionType, actionType)
                .betweenIfPresent(BaseDO::getCreateTime, operateTime)
                .orderByDesc(BaseDO::getCreateTime)
                .orderByDesc(ProductStatusLogDO::getId));
    }

    default List<ProductStatusLogDO> selectListByProductIdAndActions(Long productId, List<String> actionTypes,
                                                                     LocalDateTime startTime, LocalDateTime endTime) {
        return selectList(new LambdaQueryWrapperX<ProductStatusLogDO>()
                .eq(ProductStatusLogDO::getProductId, productId)
                .inIfPresent(ProductStatusLogDO::getActionType, actionTypes)
                .betweenIfPresent(BaseDO::getCreateTime, startTime, endTime)
                .orderByDesc(BaseDO::getCreateTime)
                .orderByDesc(ProductStatusLogDO::getId));
    }

}
