using APT.BaseData.Domain.IServices.FM;
using APT.Infrastructure.Api.Redis;
using APT.Infrastructure.Core;
using APT.PF.WebApi.Models;
using APT.Utility;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using APT.Infrastructure.Api;
namespace APT.PF.WebApi.Controllers.Api
{
    [Route("api/PF/VerifyPhone")]
    public class VerifyPhoneCodeController :CommonApiController
    {
        /// <summary>
        /// 手机验证码
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("PhoneVerifyCode")]
        public JsonActionResult<bool> PhoneNumberVerifyCode(string orgId,string uid, string random)
        {
            return SafeExecute<bool>(() =>
            {
                string code = VerifyCodeHelper.GetSingleObj().CreateVerifyCode(VerifyCodeHelper.VerifyCodeType.NumberVerifyCode, 6);
                Dictionary<string, string> dicNCode = new Dictionary<string, string>();
                dicNCode.Add("time", DateTime.Now.AddSeconds(60).ToString());
                dicNCode.Add("code", code);
                CsRedisManager.StringSet(SessionKey.VERIFY_MESSAGE_CODE + uid, dicNCode);
                //var serice = ServiceLocator.Instance.GetService<IFMSmsService>();               
                //return serice.SendMessage(new Guid(orgId), new Guid(uid), code);
                return true;
            });
        }

        /// <summary>
        /// APP手机验证码
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("AppPhoneVerifyCode")]
        public JsonActionResult<bool> AppPhoneVerifyCode(string phone)
        {
            return SafeExecute<bool>(() =>
            {
                string code = VerifyCodeHelper.GetSingleObj().CreateVerifyCode(VerifyCodeHelper.VerifyCodeType.NumberVerifyCode, 6);
                Dictionary<string, string> dicNCode = new Dictionary<string, string>();
                dicNCode.Add("time", DateTime.Now.AddSeconds(60).ToString());
                dicNCode.Add("code", code);
                CsRedisManager.StringSet(SessionKey.VERIFY_MESSAGE_CODE + phone, dicNCode);
                //var serice = ServiceLocator.Instance.GetService<IFMSmsService>();
                //return serice.SendMessage(phone, code);
                return true;
            });
        }
    }
}
