using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Nirvana.Common;
using Nirvana.Common.ApiBase;
using System.Threading.Tasks;
using YBDevice.Body.BodyFatHelper;

namespace YBDevice.NApi.Application.ThirdOpen
{
    /// <summary>
    /// 对外开放接口
    /// </summary>
    [ApiDescriptionSettings("ThirdOpen")]
    public class ThirdAppService : IDynamicApiController
    {
        private readonly IBodyFatHelperService _bodyService;

        public ThirdAppService(IBodyFatHelperService bodyService)
        {
            _bodyService = bodyService;
        }

        /// <summary>
        /// 计算结果值
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        //[ThirdAuthorizeFilter]
        public ResultInfo Body24(BodyCalcC2SDto data)
        {
            var returndata = _bodyService.CalcBodyFat(data.Weight.ToDouble(), data.Height.ToDouble(), data.Age, data.adc
                , data.sex);
            var resdata = returndata.Adapt<BodyCalcS2CDto>();
            if (resdata.standardWeight.ToDouble() <= 0)
            {
                return new ResultInfo(ResultState.FAIL, "暂不支持疑似小孩的计算", null);
            }
            else
            {
                return new ResultInfo(ResultState.SUCCESS, "success", resdata);
            }
        }

        /// <summary>
        /// 八电极计算结果值
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ResultInfo> Body120(Body120CalcC2SDto input)
        {
            var returndata = await _bodyService.CalcBody120FatAsync(input.Weight, input.Height, input.Age, input.sex, input.lefthand, input.righthand, input.leftfoot, input.rightfoot, input.body);
            var data = returndata.Adapt<OpenUserMeasureDto>();
            return new ResultInfo(ResultState.SUCCESS, "success", data);
        }

        /// <summary>
        /// 品传算法计算结果值
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public ResultInfo PCBody24(BodyCalcC2SDto data)
        {
            var returndata = _bodyService.PCCalcBodyFat(data.Weight.ToDouble(), data.Height.ToDouble(), data.Age, data.adc
                , data.sex);
            var resdata = returndata.Adapt<BodyCalcS2CDto>();
            return new ResultInfo(ResultState.SUCCESS, "success", resdata);
        }

        /// <summary>
        /// 接受转发的数据测试样例
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Post(BodyPostBodyS2SDto data)
        {
            return "success";
        }
    }
}