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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.modules.category.facade.IShopFacade;
import com.ruoyi.web.modules.store.constant.ShopConstants;
import com.ruoyi.web.modules.store.domain.BizShop;
import com.ruoyi.web.modules.store.facade.IAgriShopFacade;
import com.ruoyi.web.modules.store.mapper.BizShopMapper;

/**
 * 店铺 Facade（分类维护 + 对外下单契约）
 */
@Service
public class ShopFacadeImpl implements IShopFacade, IAgriShopFacade
{
    @Autowired
    private BizShopMapper shopMapper;

    @Override
    public void assertShopMaintable(Long shopId)
    {
        BizShop shop = shopMapper.selectById(shopId);
        if (shop == null)
        {
            throw new ServiceException("店铺不存在或已删除");
        }
    }

    @Override
    public String getShopName(Long shopId)
    {
        BizShop shop = shopMapper.selectById(shopId);
        if (shop == null)
        {
            return StringUtils.EMPTY;
        }
        return shop.getShopName();
    }

    @Override
    public String getShopStatus(Long shopId)
    {
        BizShop shop = shopMapper.selectById(shopId);
        return shop != null ? shop.getShopStatus() : null;
    }

    @Override
    public boolean isShopOpenForOrder(Long shopId)
    {
        BizShop shop = shopMapper.selectById(shopId);
        return shop != null && ShopConstants.STATUS_OPEN.equals(shop.getShopStatus());
    }
}
