using Senparc.Weixin.MP.Entities;
using Senparc.Weixin.MP.Entities.Request;
using Senparc.Weixin.MP.MessageHandlers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace ServiceWechat.Api.MessageHandlers.CustomMessageHandler
{
    public class CustomMessageHandler : MessageHandler<CustomMessageContext>
    {
        public CustomMessageHandler(Stream inputStream, PostModel postModel)
            : base(inputStream, postModel)
        {

        }

        /// <summary>
        /// 默认回复
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase DefaultResponseMessage(IRequestMessageBase requestMessage)
        {
            var responseMessage = base.CreateResponseMessage<ResponseMessageText>(); //ResponseMessageText也可以是News等其他类型
            responseMessage.Content = "我是默认的自动回复 么么哒～～～。";
            return responseMessage;
        }



        /// <summary>
        /// 处理用户发来的文本信息
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage)
        {
            //requestMessage.FromUserName也可以直接写成base.WeixinOpenId
            var openId = base.WeixinOpenId;
            //客户发来的文本信息
            var content = requestMessage.Content;

            //【TODO:查询已配置的文本回复信息】


            var responseMessage = base.CreateResponseMessage<ResponseMessageText>();
            responseMessage.Content = $"您的OpenID是{openId}。\r\n您发送了文字信息：{content}";
            return responseMessage;
        }


    }
}
