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

/**
 * 库存Repository
 * 对应PHP Stock模型
 */
@Mapper
public interface StockRepository extends BaseMapper<Stock> {

    /**
     * 根据SKU编码和仓库ID查询库存
     */
    @Select("SELECT * FROM stocks WHERE sku_code = #{skuCode} AND warehouse_id = #{warehouseId} LIMIT 1")
    Stock findBySkuCodeAndWarehouseId(@Param("skuCode") String skuCode, @Param("warehouseId") Long warehouseId);

    /**
     * 分页查询库存列表（带条件）
     */
    IPage<Stock> findByConditions(Page<Stock> page,
                                  @Param("skuCode") String skuCode,
                                  @Param("skuName") String skuName,
                                  @Param("warehouseId") Long warehouseId,
                                  @Param("lowStock") Boolean lowStock);

    /**
     * 查询低库存预警列表
     */
    IPage<Stock> findLowStockWarnings(Page<Stock> page, @Param("warehouseId") Long warehouseId);
}
