using Bogus.DataSets;

using CloudGaming.Api.Base;
using CloudGaming.Code.Account;
using CloudGaming.Code.AppExtend;
using CloudGaming.Code.DataAccess;
using CloudGaming.Code.MiddlewareExtend;
using CloudGaming.DtoModel.Account;
using CloudGaming.DtoModel.Account.Login;
using CloudGaming.DtoModel.Account.User;
using CloudGaming.DtoModel.Account.UserDiamondConsume;
using CloudGaming.GameModel.Db.Db_Ext;

using HuanMeng.DotNetCore.AttributeExtend;
using HuanMeng.DotNetCore.Base;

using HuanMeng.DotNetCore.Utility;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace CloudGaming.Api.Controllers;

/// <summary>
/// 账号管理
/// </summary>
public class AccountController : CloudGamingControllerBase
{
    public AccountController(IServiceProvider _serviceProvider) : base(_serviceProvider)
    {
    }

    /// <summary>
    /// 发送验证码
    /// </summary>
    /// <param name="phoneNumber"></param>
    /// <returns></returns>
    [HttpPost]
    [Message("发送成功")]
    public async Task<bool> SendPhoneNumber([FromBody] PhoneNumberRequest phoneNumber)
    {
        AccountBLL account = new AccountBLL(ServiceProvider);
        return await account.SendPhoneNumber(phoneNumber.PhoneNumber);
    }
    /// <summary>
    ///登录接口
    /// </summary>
    /// <param name="baseLogin"> 
    /// 登录数据格式(设备号的目的是用于以后的多设备登录)(设备号可不给)<br />
    /// 短信登录：{"phoneNumber":"手机号","verificationCode":"验证码","deviceNumber":"设备号"}<br />
    /// token登录（请求标头带上Authorized的token即可） {"deviceNumber":"设备号"}<br />
    /// </param>
    /// <returns></returns>
    [HttpPost]
    public async Task<AccountLogInResponse> LoginAsync([FromBody] BaseLoginParams? baseLogin)
    {
        AccountBLL account = new AccountBLL(ServiceProvider);
        return await account.LoginAsync();
    }

    /// <summary>
    /// 获取用户信息
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Authorize]
    public async Task<UserInfoDto> GetUserInfo()
    {
        AccountBLL account = new AccountBLL(ServiceProvider);
        return await account.GetUserInfo();
    }

    /// <summary>
    /// 实名认证接口（需要登录）
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [Authorize]
    public async Task<BaseResponse<bool>> RealAuthentication([FromBody] UserRealAuthenticationRequest authenticationRequest)
    {
        AccountBLL account = new AccountBLL(ServiceProvider);
        return await account.RealAuthentication(authenticationRequest.UserName, authenticationRequest.IdCard, authenticationRequest.DeviceNumber);
    }

    /// <summary>
    /// 资产收入、支出（需要登录）
    /// </summary>
    /// <param name="consumeType">0支出，1收入</param>
    /// <returns></returns>
    [HttpGet]
    [Authorize]
    public async Task<List<UserDiamondConsumeDto>> GetUserDiamondConsumeList([FromQuery] int consumeType)
    {
        AccountBLL account = new AccountBLL(ServiceProvider);
        return await account.GetUserDiamondConsumeList(consumeType);
    }

    /// <summary>
    /// 修改用户昵称（需要登录）
    /// </summary>
    /// <param name="accountNickNameRequest"></param>
    /// <returns></returns>
    [HttpPost]
    [Authorize]
    public async Task<BaseResponse<bool>> UpdateUserNickName([FromBody] AccountNickNameRequest accountNickNameRequest)
    {
        AccountBLL account = new AccountBLL(ServiceProvider);
        return await account.UpdateUserNickName(accountNickNameRequest.NickName);
    }

    /// <summary>
    /// 退出app
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<bool> ExitApp()
    {
        AccountBLL account = new AccountBLL(ServiceProvider);
        await account.ExitApp();
        return true;
    }

    /// <summary>
    /// 账号注销
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [Message("注销成功")]
    public async Task<bool> AccountLogOff()
    {
        AccountBLL account = new AccountBLL(ServiceProvider);
        await account.AccountLogOff();
        return true;
    }

}
