package com.erp.inventory.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.erp.inventory.entity.StockLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;

/**
 * 库存流水Repository
 * 对应PHP StockLog模型
 */
@Mapper
public interface StockLogRepository extends BaseMapper<StockLog> {

    /**
     * 分页查询库存流水（带条件）
     */
    IPage<StockLog> findByConditions(Page<StockLog> page,
                                      @Param("skuCode") String skuCode,
                                      @Param("warehouseId") Long warehouseId,
                                      @Param("type") String type,
                                      @Param("orderId") Long orderId,
                                      @Param("deliveryNo") String deliveryNo,
                                      @Param("startDate") LocalDateTime startDate,
                                      @Param("endDate") LocalDateTime endDate);

    /**
     * 根据预扣凭证查找预扣记录
     */
    StockLog findByReserveToken(@Param("reserveToken") String reserveToken, @Param("orderId") Long orderId);
}
