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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.modules.category.facade.IGoodsFacade;
import com.ruoyi.web.modules.goods.mapper.BizGoodsFreightMapper;
import com.ruoyi.web.modules.goods.mapper.BizGoodsMapper;
import com.ruoyi.web.modules.store.facade.IGoodsShopFacade;

/**
 * 商品 Facade（分类删前、店铺删前）
 */
@Service
public class GoodsFacadeImpl implements IGoodsFacade, IGoodsShopFacade
{
    @Autowired
    private BizGoodsMapper goodsMapper;

    @Autowired
    private BizGoodsFreightMapper goodsFreightMapper;

    @Override
    public boolean existsByCategoryId(Long categoryId)
    {
        if (categoryId == null)
        {
            return false;
        }
        return goodsMapper.countByCategoryId(categoryId) > 0;
    }

    @Override
    public boolean existsByShopCategoryId(Long shopCategoryId)
    {
        if (shopCategoryId == null)
        {
            return false;
        }
        return goodsMapper.countByShopCategoryId(shopCategoryId) > 0;
    }

    @Override
    public boolean existsByAttrTemplateId(Long templateId)
    {
        if (templateId == null)
        {
            return false;
        }
        return goodsMapper.countByAttrTemplateId(templateId) > 0;
    }

    @Override
    public boolean existsByFreightTemplateId(Long templateId)
    {
        if (templateId == null)
        {
            return false;
        }
        return goodsFreightMapper.countByFreightTemplateId(templateId) > 0;
    }

    @Override
    public boolean hasBlockingGoodsForShopDelete(Long shopId)
    {
        if (shopId == null)
        {
            return false;
        }
        return goodsMapper.countBlockingByShopId(shopId) > 0;
    }
}
