using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
using Nirvana.Common.ApiBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using YBDevice.Entity;

namespace YBDevice.NApi.Application.BusinessClient.AccountInfo
{
    /// <summary>
    /// 账户登录注册相关
    /// </summary>
    [ApiDescriptionSettings("BusinessClient")]
    public class AccountAppService : IDynamicApiController
    {
        private readonly IAccountService _accountService;

        public AccountAppService(IAccountService accountService)
        {
            _accountService = accountService;
        }
        /// <summary>
        /// 根据手机号进行注册
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<ResultInfo> RegisterAsync(BusinessRegDto model)
        {
            return await _accountService.RegisterAsync(model);
        }

        /// <summary>
        /// 小程序登录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<ResultInfo> OnLoginAsync(WXOpenLoginSubmitModel model)
        {
            return await _accountService.OnLoginAsync (model);
        }
        /// <summary>
        /// 根据手机号和密码进行登录
        /// </summary>
        /// <param name="businessLoginDto"></param>
        /// <returns></returns>
        public async Task<ResultInfo> LoginAsync(BusinessLoginDto businessLoginDto)
        {
            return await _accountService.LoginAsync(businessLoginDto);
        }
        /// <summary>
        /// 手机号快捷登录,如果未注册则自动进行注册,默认密码同手机号
        /// </summary>
        /// <param name="businessLoginDto"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SLoginAsync(BusinessQLoginDto businessLoginDto)
        {
            return await _accountService.SLoginAsync(businessLoginDto);
        }
        /// <summary>
        /// 手机号授权,如果未注册会自动进行注册
        /// </summary>
        /// <param name="businessLoginDto"></param>
        /// <returns></returns>
        public async Task<ResultInfo> DecryptPhoneAsync(BusinessDecryptSubmitModel businessLoginDto)
        {
            return await _accountService.DecryptPhoneAsync(businessLoginDto);
        }
        /// <summary>
        /// 发送短信验证码
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> SendCodeAsync(string phone)
        {
            return await _accountService.SendCodeAsync(phone);
        }
    }
}
