using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Nirvana.Common;
using Nirvana.Common.ApiBase;
using System;
using System.Threading.Tasks;
using YBDevice.Entity;

namespace YBDevice.NApi.Controllers
{
    /// <summary>
    /// 广告管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AdController : ControllerBase
    {
        private readonly IZXService _zxService;
        private readonly IHttpContextAccessor _httpContextAccessor;
        public AdController(IZXService zXService, IHttpContextAccessor httpContextAccessor)
        {
            _zxService = zXService;
            _httpContextAccessor = httpContextAccessor;
        }
        /// <summary>
        /// 科普资讯列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetInfoListAsync([FromBody] ParamQuery param)
        {
            var token = _httpContextAccessor.HttpContext.Request.Headers["token"].ToString();
            var ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
            await BaseService.DecodeTokenAsync(token, ip);
            var list = await _zxService.GetInfoListAsync(param);
            return new ResultInfo(ResultState.SUCCESS, "success", list);
        }
        /// <summary>
        /// 科普资讯详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> InfoDetailAsync(Guid id)
        {
            var data = await _zxService.InfoDetailAsync(id);
            return data;
        }

        /// <summary>
        /// 更新点击数
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> UpdateClickCountAsync(Guid id)
        {
            return await _zxService.UpdateClickCountAsync(id);
        }

        /// <summary>
        /// 科普资讯标签列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> GetInfoTagListAsync(string appid="")
        {
            var data = await _zxService.GetInfoTagListAsync(appid);
            return data;
        }

        /// <summary>
        /// 轮播图列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetBannerListAsync([FromBody] BannerListC2SDto param)
        {
            //var token = _httpContextAccessor.HttpContext.Request.Headers["token"].ToString();
            //var ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
            //await BaseService.DecodeTokenAsync(token, ip);
            var list = await _zxService.GetBannerListAsync(param);
            return new ResultInfo(ResultState.SUCCESS, "success", list);
        }
        /// <summary>
        /// 轮播图详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> BannerDetailAsync(int id)
        {
            var data = await _zxService.BannerDetailAsync(id);
            return data;
        }

    }
}
