using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Senparc.Weixin.MP.AdvancedAPIs;
using ServiceWechat.Api.Controllers.Base;
using ServiceWechat.Utility;

namespace ServiceWechat.Api.Controllers.WechatApis
{
    [Route("WechatApi/TemplateMsg/[action]")]
    public class TemplateMsgController : BaseController
    {
        private readonly string Token;
        private readonly string AppId;
        private readonly string AppSecret;
        private readonly string EncodingAESKey;
        public TemplateMsgController(IConfiguration configuration)
        {
            Token = configuration["WechatStatic:Token"];
            AppId = configuration["WechatStatic:AppId"];
            AppSecret = configuration["WechatStatic:AppSecret"];
            EncodingAESKey = configuration["WechatStatic:EncodingAESKey"];
        }

        ///// <summary>
        ///// 发送模板消息【需要安全验证】
        ///// </summary>
        ///// <returns></returns>
        //public JsonResult Send()
        //{
        //    //根据userId获取关注该公众号的微信号


        //    var url = "url";
        //    var first = "你好，你有一条新的任务";
        //    var result = TemplateApi.SendTemplateMessage(
        //    AppId,
        //    "openId",
        //    "TempleteMessageId",
        //    url,
        //       new
        //       {
        //           first = new { value = first, color = "#173177" },
        //           keyword1 = new { value = place, color = "#173177" },
        //           keyword2 = new { value = detail, color = "#173177" },
        //           keyword3 = new { value = username, color = "#173177" },
        //           keyword4 = new { value = phone, color = "#173177" },
        //           remark = new { value = string.IsNullOrWhiteSpace(remark) ? "请尽快处理！" : remark, color = "#173177" },
        //       });
        //    return Success("OK");
        //}


        /// <summary>
        /// 获取已添加至帐号下所有模板列表
        /// </summary>
        /// <returns></returns>
        public async Task<JsonResult> GetList()
        {
            var result = await TemplateApi.GetPrivateTemplateAsync(AppId);
            return Success("ok", result);
        }
    }
}