package com.game.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;

import com.game.business.dto.AppItemCountDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.game.business.mapper.AppGameItemMapper;
import com.game.business.domain.AppGameItem;
import com.game.business.service.IAppGameItemService;
import com.game.common.annotation.DataSource;
import com.game.common.enums.DataSourceType;

/**
 * 游戏选项Service业务层处理
 *
 * @author game
 * @date 2024-06-29
 */
@Service
public class AppGameItemServiceImpl extends ServiceImpl<AppGameItemMapper, AppGameItem> implements IAppGameItemService {
    @Autowired
    private AppGameItemMapper appGameItemMapper;

    /**
     * 查询游戏选项
     *
     * @param id 游戏选项主键
     * @return 游戏选项
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public AppGameItem selectAppGameItemById(Long id) {
        return appGameItemMapper.selectAppGameItemById(id);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public AppGameItem selectAppGameItemByGameIdAndItemLocation(Long gameId, String itemLocation) {

        LambdaQueryWrapper<AppGameItem> queryWrapper = Wrappers.lambdaQuery();;
        queryWrapper.eq(AppGameItem::getGameId, gameId);
        queryWrapper.eq(AppGameItem::getItemLocation, itemLocation);

        return appGameItemMapper.selectOne(queryWrapper);
    }

    /**
     * 查询游戏选项列表
     *
     * @param appGameItem 游戏选项
     * @return 游戏选项
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<AppGameItem> selectAppGameItemList(AppGameItem appGameItem) {
        return appGameItemMapper.selectAppGameItemList(appGameItem);
    }

    /**
     * 新增游戏选项
     *
     * @param appGameItem 游戏选项
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int insertAppGameItem(AppGameItem appGameItem) {
            return appGameItemMapper.insertAppGameItem(appGameItem);
    }

    /**
     * 修改游戏选项
     *
     * @param appGameItem 游戏选项
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int updateAppGameItem(AppGameItem appGameItem) {
        return appGameItemMapper.updateAppGameItem(appGameItem);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public int updateLotteryCount(AppGameItem appGameItem) {
        return appGameItemMapper.updateLotteryCount(appGameItem);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public int updateConsecutive(AppItemCountDTO appGameItem) {
        return appGameItemMapper.updateConsecutive(appGameItem);
    }

    /**
     * 批量删除游戏选项
     *
     * @param ids 需要删除的游戏选项主键
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int deleteAppGameItemByIds(Long[] ids) {
        return appGameItemMapper.deleteAppGameItemByIds(ids);
    }

    /**
     * 删除游戏选项信息
     *
     * @param id 游戏选项主键
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int deleteAppGameItemById(Long id) {
        return appGameItemMapper.deleteAppGameItemById(id);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public boolean emptyLotteryCount() {
        return appGameItemMapper.emptyLotteryCount() > 0;
    }
}