using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Nirvana.Common.ApiBase;
using System;
using System.Threading.Tasks;
using YBDevice.NApi.Application.ThirdClient.Family;

namespace YBDevice.NApi.Application.ThirdClient
{

    /// <summary>
    /// 第三方相关调用
    /// </summary>
    [ApiDescriptionSettings("ThirdClient")]
    [Authorize]
    public class OpenAppService : IDynamicApiController
    {
        private readonly IOpenService _openService;
        private readonly IOpenFamilyService _familyService;
        public OpenAppService(IOpenService openService, IOpenFamilyService familyService)
        {
            _openService = openService;
            _familyService = familyService;
        }
        /// <summary>
        /// BMI计算
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [AllowAnonymous]
        public async Task<ResultInfo> CalcBmiAsync(BmiInfoC2SDto data)
        {
            return await _openService.CalcBmiAsync(data);
        }
        /// <summary>
        /// 身高预测
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [AllowAnonymous]
        public async Task<ResultInfo> CalcPredictHeightAsync(HeightInfoC2SDto data)
        {
            return await _openService.CalcPredictHeightAsync(data);
        }
        /// <summary>
        /// 登录接口
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [AllowAnonymous]
        public async Task<ResultInfo> OnLoginAsync(TouTiaoLoginC2SDto data)
        {
            return await _openService.OnLoginAsync(data);
        }
        /// <summary>
        /// 解密用户资料,如果未注册则自动进行注册,否则更新资料
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [AllowAnonymous]
        public async Task<ResultInfo> DecryptDataAsync(DecryptUserInfoC2SDto data)
        {
            return await _openService.DecryptDataAsync(data);
        }
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [AllowAnonymous]
        public async Task<ResultInfo> RegisterAsync(SubmitUserInfoC2SDto data)
        {
            return await _openService.RegisterAsync(data);
        }
        /// <summary>
        /// 获取测量记录列表
        /// </summary>
        /// <param name="familyid">家庭成员ID</param>
        /// <param name="page">页码</param>
        /// <param name="pagesize">每页显示数量</param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetResultListAsync(Guid familyid, int page = 1, int pagesize = 10)
        {
            return await _openService.GetResultListAsync(familyid, page, pagesize);
        }

        /// <summary>
        /// 家庭成员列表
        /// </summary>
        /// <returns></returns>
        public async Task<ResultInfo> GetFamilyListAsync()
        {
            return await _familyService.GetListAsync();
        }
        /// <summary>
        /// 修改家庭成员资料
        /// </summary>
        /// <returns></returns>
        public async Task<ResultInfo> SubmitFamilyAsync(FamilySubmitC2SDto data)
        {
            return await _familyService.SubmitAsync(data);
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="familyid">家庭成员ID</param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetUserInfoAsync(Guid? familyid)
        {
            return await _openService.GetUserInfoAsync(familyid);
        }
        /// <summary>
        /// 添加测量记录
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<ResultInfo> AddResultAsync(InsertResultC2SDto data)
        {
            return await _openService.AddResultAsync(data);
        }
        /// <summary>
        /// 退出登录
        /// </summary>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> OutLoginAsync(string sessionId)
        {
            return await _openService.OutLoginAsync(sessionId);
        }
        /// <summary>
        /// 修改用户资料
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SubmitUserInfoAsync(SumitUserInfoC2SDto data)
        {
            return await _openService.SubmitUserInfoAsync(data);
        }
    }
}
