package com.ruoyi.web.modules.category.facade.impl;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.modules.category.facade.ICategoryFacade;
import com.ruoyi.web.modules.category.facade.IShopGoodsCategoryFacade;
import com.ruoyi.web.modules.category.vo.CategoryLevel2OptionVO;
import com.ruoyi.web.modules.category.vo.ShopGoodsCategoryOptionVO;

/**
 * 店铺商品分类 Facade（biz_goods_category 本店二级）
 */
@Service
public class ShopGoodsCategoryFacadeImpl implements IShopGoodsCategoryFacade
{
    @Autowired
    private ICategoryFacade categoryFacade;

    @Override
    public List<ShopGoodsCategoryOptionVO> listOptionsByShopId(Long shopId, boolean visibleOnly)
    {
        if (shopId == null || shopId <= 0)
        {
            return new ArrayList<>();
        }
        List<CategoryLevel2OptionVO> level2List = categoryFacade.listLevel2ByShopId(shopId);
        List<ShopGoodsCategoryOptionVO> options = new ArrayList<>();
        for (CategoryLevel2OptionVO item : level2List)
        {
            if (visibleOnly && !categoryFacade.isCategoryVisible(item.getCategoryId()))
            {
                continue;
            }
            options.add(new ShopGoodsCategoryOptionVO(item.getCategoryId(), item.getLabel(), null));
        }
        return options;
    }
}
