package com.erp.product.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.erp.product.entity.ComboItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 组套子项Mapper接口
 */
@Mapper
public interface ComboItemRepository extends BaseMapper<ComboItem> {
    
    /**
     * 根据组套商品ID查询所有子项
     */
    @Select("SELECT * FROM combo_items WHERE combo_goods_id = #{comboGoodsId}")
    List<ComboItem> findByComboGoodsId(@Param("comboGoodsId") Long comboGoodsId);
    
    /**
     * 根据子商品ID查询被哪些组套商品引用
     */
    @Select("SELECT combo_goods_id FROM combo_items WHERE goods_id = #{goodsId}")
    List<Long> findComboGoodsIdsByGoodsId(@Param("goodsId") Long goodsId);
    
    /**
     * 删除指定组套商品的所有子项
     */
    @Delete("DELETE FROM combo_items WHERE combo_goods_id = #{comboGoodsId}")
    void deleteByComboGoodsId(@Param("comboGoodsId") Long comboGoodsId);
}
