using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Nirvana.Common.ApiBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using YBDevice.Api.DBServices;
using YBDevice.Entity;

namespace YBDevice.Api.Controllers
{
    /// <summary>
    /// 用户管理接口
    /// </summary>
    public class UserController : BaseController
    {
        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> GetUserInfoAsync()
        {
            return await new UserApp().GetUserInfoAsync();
        }
        /// <summary>
        /// 获取用户测量数据
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetMeasureInfoAsync([FromBody] UserMeasureInfoModel data)
        {
            return await new UserApp().GetMeasureInfoAsync(data);
        }

        /// <summary>
        /// 解密手机号
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> DecryptPhoneAsync([FromBody] WxOpenDecryptSubmitModel model)
        {
            return await new UserApp().DecryptPhoneAsync(model);
        }


        /// <summary>
        /// 解密微信运动
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> DecryptWxRunAsync([FromBody] WxOpenDecryptSubmitModel model)
        {
            var wxrun = await WxRun.DecodeWxRunBySessionIdAsync(model.sessionId, model.encryptedData, model.iv);
            return new ResultInfo(ResultState.SUCCESS, "success", wxrun.stepInfoList);
        }

    }
}
