package pposRequest

import (
	"PPOSUtils/utils"
	"errors"
	"net/url"
)

//NewWxMpSmsTempSend 短信模板发送
func (that *PPOSClient) NewWxMpSmsTempSend() *WxMpSmsTempSendRequest {
	return &WxMpSmsTempSendRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/wxMp/smsTemp/send",
		},
		SignName:     "运动馆家",
		SmsType:      11,
		SmsSendAsync: 0,
		SmsCallback:  "http://",
	}
}

type WxMpSmsTempSendResponse struct {
	RecordId  string `json:"record_id"`
	SmsStatus int64  `json:"sms_status"`
}

//CfgTradeGetByIdRequest ...
type WxMpSmsTempSendRequest struct {
	Request
	TempId       int64  `json:"temp_id"`        //消息模板id
	SmsType      int64  `json:"sms_type"`       //消息发送方式(11阿里大于， 21站内消息)
	SignName     string `json:"sign_name"`      //短信签名
	TempParams   string `json:"temp_params"`    //消息模板变量
	SmsMobile    string `json:"sms_mobile"`     //手机号码
	SmsCallback  string `json:"sms_callback"`   //状态回调地址
	SmsSendAsync int64  `json:"sms_send_async"` //消息发送的方式，0同步（默认），1异步>
}

func (that *WxMpSmsTempSendRequest) SetTempId(value int64) *WxMpSmsTempSendRequest {
	that.TempId = value
	return that
}
func (that *WxMpSmsTempSendRequest) SetSmsType(value int64) *WxMpSmsTempSendRequest {
	that.SmsType = value
	return that
}
func (that *WxMpSmsTempSendRequest) SetSignName(value string) *WxMpSmsTempSendRequest {
	that.SignName = value
	return that
}
func (that *WxMpSmsTempSendRequest) SetSmsParams(value string) *WxMpSmsTempSendRequest {
	that.TempParams = value
	return that
}
func (that *WxMpSmsTempSendRequest) SetSmsMobile(value string) *WxMpSmsTempSendRequest {
	that.SmsMobile = value
	return that
}
func (that *WxMpSmsTempSendRequest) SetSmsCallback(value string) *WxMpSmsTempSendRequest {
	that.SmsCallback = value
	return that
}
func (that *WxMpSmsTempSendRequest) SetSmsSendAsync(value int64) *WxMpSmsTempSendRequest {
	that.SmsSendAsync = value
	return that
}

//Params ...
func (that *WxMpSmsTempSendRequest) Params() (url.Values, error) {
	var m = make(url.Values)
	m.Set("temp_id", utils.ToString(that.TempId))
	m.Set("sms_type", utils.ToString(that.SmsType))
	m.Set("sign_name", utils.ToString(that.SignName))
	m.Set("temp_params", utils.ToString(that.TempParams))
	m.Set("sms_mobile", utils.ToString(that.SmsMobile))
	m.Set("sms_callback", utils.ToString(that.SmsCallback))
	m.Set("sms_send_async", utils.ToString(that.SmsSendAsync))
	return m, nil
}

//Do ...
func (that *WxMpSmsTempSendRequest) Do() (*WxMpSmsTempSendResponse, error) {
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_sliceData, _ok := _data.(map[string]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	//
	_tmp := new(WxMpSmsTempSendResponse)
	if _err := that.ParseResponeMp(_tmp, _sliceData); _err != nil {
		return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
	}
	//
	return _tmp, nil
}
