using CloudGaming.Api.Base;
using CloudGaming.Code.Cache;
using CloudGaming.Code.DataAccess;
using CloudGaming.Code.Game;
using CloudGaming.Code.MiddlewareExtend;
using CloudGaming.DtoModel.Game;
using CloudGaming.GameModel.Db.Db_Game;
using CloudGaming.Model.DbSqlServer.Db_User;

using HuanMeng.DotNetCore.Base;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace CloudGaming.Api.Controllers
{
    /// <summary>
    /// 游戏控制器
    /// </summary>
    public class GameController : CloudGamingControllerBase
    {
        public GameController(IServiceProvider _serviceProvider) : base(_serviceProvider)
        {
        }


        /// <summary>
        /// 游戏类型列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [RedisCache(2, 0, 0)]
        public async Task<List<GameExtendedAttribute>> GetGameTypeListAsync()
        {
            GameBLL gamebll = new GameBLL(this.ServiceProvider);
            return await gamebll.GetGameTypeListAsync();
        }


        /// <summary>
        /// 根据游戏类型Id 获取游戏列表
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        [HttpGet]
        [RedisCache(2, 5, 0)]
        public async Task<List<GameListDto>> GetGameListAsync([FromQuery] int typeId)
        {
            if (typeId == 0)
            {
                return new List<GameListDto>();
            }
            GameBLL gamebll = new GameBLL(this.ServiceProvider);
            return await gamebll.GetGameListAsync(typeId);
        }

        /// <summary>
        /// 获取游戏详情
        /// </summary>
        /// <param name="gameId"></param>
        /// <returns></returns>
        [HttpGet]
        //[RedisCache(2, 2, 0)]
        public async Task<GameInfoDto> GetGameInfo([FromQuery] string gameId)
        {
            GameBLL gamebll = new GameBLL(this.ServiceProvider);
            return await gamebll.GetGameInfo(gameId);
        }
        /// <summary>
        /// 根据游戏类型Id 获取游戏列表
        /// </summary>
        /// <param name="gameId"></param>
        /// <returns></returns>
        [HttpGet]
        [RedisCache(0, 5, 0)]
        public List<GameListDto> GameRecommendations([FromQuery] string? gameId)
        {

            GameBLL gamebll = new GameBLL(this.ServiceProvider);
            return gamebll.GameRecommendations(gameId);
        }
        /// <summary>
        /// 游戏搜索
        /// </summary>
        /// <param name="gameId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<GameListDto>> GameSearch([FromQuery] string? gameId)
        {

            GameBLL gamebll = new GameBLL(this.ServiceProvider);
            return await gamebll.GameSearch(gameId);
        }

        /// <summary>
        /// 游戏热度搜索
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<string>> GameHotSearch()
        {

            GameBLL gamebll = new GameBLL(this.ServiceProvider);
            return await gamebll.GameHotSearch();
        }


        /// <summary>
        /// 我的收藏列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<GameListDto>> GetGameCollect()
        {
            GameBLL gamebll = new GameBLL(this.ServiceProvider);
            return await gamebll.GetGameCollect();
        }
        /// <summary>
        /// 收藏游戏
        /// </summary>
        /// <param name="collectRequest"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<BaseResponse<bool>> GameCollect([FromBody] GameRequest collectRequest)
        {
            if (string.IsNullOrEmpty(collectRequest.GameId))
            {
                return new BaseResponse<bool>(ResponseCode.Error, "游戏不能未空");
            }
            GameBLL gamebll = new GameBLL(this.ServiceProvider);
            return await gamebll.GameCollect(collectRequest.GameId);
        }


        /// <summary>
        /// 游玩历史
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public async Task<List<GameHistoryListDto>> GetGameHistory()
        {
            GameBLL gamebll = new GameBLL(this.ServiceProvider);
            return await gamebll.GetGameHistory();
        }

        /// <summary>
        /// 游戏时长排行榜,十分钟更新一次
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<GamePlayTimeInfoDto> GamePlayTimeList([FromQuery] string gameId)
        {
            GameBLL gamebll = new GameBLL(this.ServiceProvider);
            return await gamebll.GamePlayTimeList(gameId);
        }


    }
}
