package com.ruoyi.bst.suit.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.ruoyi.bst.store.domain.StoreQuery;
import com.ruoyi.bst.store.domain.StoreVO;
import com.ruoyi.bst.store.service.StoreService;
import com.ruoyi.bst.storeStaff.domain.enums.StoreStaffPermission;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bst.suit.mapper.SuitMapper;
import com.ruoyi.bst.suit.domain.Suit;
import com.ruoyi.bst.suit.domain.SuitVO;
import com.ruoyi.bst.suit.domain.SuitQuery;
import com.ruoyi.bst.suit.service.SuitService;

/**
 * 套餐Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-25
 */
@Service
public class SuitServiceImpl implements SuitService
{
    @Autowired
    private SuitMapper suitMapper;
    @Autowired
    private StoreService storeService;

    /**
     * 查询套餐
     *
     * @param suitId 套餐主键
     * @return 套餐
     */
    @Override
    public SuitVO selectSuitBySuitId(Long suitId)
    {
        return suitMapper.selectSuitBySuitId(suitId);
    }

    /**
     * 查询套餐列表
     *
     * @param suit 套餐
     * @return 套餐
     */
    @Override
    public List<SuitVO> selectSuitList(SuitQuery suit)
    {
        return suitMapper.selectSuitList(suit);
    }

    /**
     * 新增套餐
     *
     * @param suit 套餐
     * @return 结果
     */
    @Override
    public int insertSuit(Suit suit)
    {
        suit.setCreateTime(DateUtils.getNowDate());
        return suitMapper.insertSuit(suit);
    }

    /**
     * 修改套餐
     *
     * @param suit 套餐
     * @return 结果
     */
    @Override
    public int updateSuit(Suit suit)
    {
        StoreVO StoreVO = storeService.selectStoreById(suit.getStoreId());
        ServiceUtil.assertion(StoreVO==null,"当前店铺不存在");
        suit.setUserId(StoreVO.getUserId());
        return suitMapper.updateSuit(suit);
    }

    /**
     * 批量删除套餐
     *
     * @param suitIds 需要删除的套餐主键
     * @return 结果
     */
    @Override
    public int deleteSuitBySuitIds(List<Long> suitIds)
    {
        return suitMapper.deleteSuitBySuitIds(suitIds);
    }

    /**
     * 删除套餐信息
     *
     * @param suitId 套餐主键
     * @return 结果
     */
    @Override
    public int deleteSuitBySuitId(Long suitId)
    {
        return suitMapper.deleteSuitBySuitId(suitId);
    }


    /**
     * 查询套餐
     *
     * @param suitId 店铺主键
     * @return 店铺
     */
    @Override
    public SuitVO selectSuitById(Long suitId, boolean scope)
    {
        if (suitId == null) {
            return null;
        }
        SuitQuery query = new SuitQuery();
        query.setSuitId(suitId);
        query.setScope(scope);
        query.addStorePermission(StoreStaffPermission.SUIT_EDIT.getCode());
        return this.selectOne(query);
    }

    @Override
    public SuitVO selectOne(SuitQuery query) {
        PageHelper.startPage(1, 1);
        List<SuitVO> list = suitMapper.selectSuitList(query);
        return CollectionUtils.firstElement(list);
    }

    /**
     * 逻辑删除套餐
     *
     * @param ids 需要删除的套餐主键集合
     * @return 结果
     */
    @Override
    public int logicDel(List<Long> ids)
    {
        return suitMapper.logicDel(ids);
    }
}
