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

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.ProductRequirementStatusLogDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collections;
import java.util.List;

/**
 * 产品需求状态变更日志 Mapper
 */
@Mapper
public interface ProductRequirementStatusLogMapper extends BaseMapperX<ProductRequirementStatusLogDO> {

    /**
     * 根据需求ID查询状态变更日志列表
     */
    default List<ProductRequirementStatusLogDO> selectListByRequirementId(Long requirementId) {
        return selectList(new LambdaQueryWrapperX<ProductRequirementStatusLogDO>()
                .eq(ProductRequirementStatusLogDO::getRequirementId, requirementId)
                .orderByDesc(ProductRequirementStatusLogDO::getCreateTime));
    }

    /**
     * 根据需求ID集合和目标状态集合查询状态变更日志。
     */
    default List<ProductRequirementStatusLogDO> selectListByRequirementIdsAndToStatuses(List<Long> requirementIds,
                                                                                        List<String> toStatuses) {
        if (requirementIds == null || requirementIds.isEmpty()
                || toStatuses == null || toStatuses.isEmpty()) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapperX<ProductRequirementStatusLogDO>()
                .in(ProductRequirementStatusLogDO::getRequirementId, requirementIds)
                .in(ProductRequirementStatusLogDO::getToStatus, toStatuses)
                .orderByDesc(ProductRequirementStatusLogDO::getCreateTime)
                .orderByDesc(ProductRequirementStatusLogDO::getId));
    }

}
