using Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.BaseApp.Subscribe;
using OpenAuth.App.ServiceApp;
using OpenAuth.App.ServiceApp.Response;
using OpenAuth.Repository.Domain;

namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
    /// <summary>
    /// 消息推送模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LasaPlatformPushController : ControllerBase
    {
        private readonly LasaPlatformPushApp _app;
        public LasaPlatformPushController(LasaPlatformPushApp app)
        {
            _app = app;
        }
        /// <summary>
        /// 获取推送平台列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key">平台名称</param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<LasaPlatform>>>> GetPlatformList(int page, int limit, string key)
        {
            var result = new Response<PageInfo<List<LasaPlatform>>>();
            try
            {
                result = await _app.GetPlatformList(page, limit, key);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 添加平台
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> AddPlatform(LasaPlatform info)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.AddPlatform(info);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 修改平台
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> UpdatePlatform(LasaPlatform info)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.UpdatePlatform(info);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 删除平台
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> DeletePlatform(string id)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.DeletePlatform(id);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }

        #region 算法推送记录
        /// <summary>
        /// 获取推送平台列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key">平台名称</param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<LasaTaskAiLogResp>>>> GetAiLogList(int page, int limit, string key)
        {
            var result = new Response<PageInfo<List<LasaTaskAiLogResp>>>();
            try
            {
                result = await _app.GetAiLogList(page, limit, key);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        #endregion


        #region 推送统计
        /// <summary>
        /// 多平台推送线索
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<List<PlatformDashboardResp>>> TaskAiStatistics()
        {
            var result = new Response<List<PlatformDashboardResp>>();
            try
            {
                result = await _app.TaskAiStatistics();
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 统计图表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<List<WeekPushChartResp>>> GetWeekPushChart()
        {
            var result = new Response<List<WeekPushChartResp>>();
            try
            {
                result = await _app.GetWeekPushChart();
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        #endregion
    }
}
