package cooper

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

//微信消息推送
func (that *CooperClient) NewWxApiSendMessageRequest() *WxApiSendMessageRequest {
	return &WxApiSendMessageRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/wxApi/send/message",
		},
	}
}

//WxApiSendMessageRequest ...
type WxApiSendMessageRequest struct {
	Request
}

//SetTmpId...
func (that *WxApiSendMessageRequest) SetTmpId(value string) *WxApiSendMessageRequest {
	that.initParams()
	that.params.Set("tmp_id", value) //微信模板ID
	return that
}

//SetOpenID..
func (that *WxApiSendMessageRequest) SetOpenID(value string) *WxApiSendMessageRequest {
	that.initParams()
	that.params.Set("open_id", value) //接收人、微信openID
	return that
}
func (that *WxApiSendMessageRequest) SetTempParams(value string) *WxApiSendMessageRequest {
	that.initParams()
	that.params.Set("data", value) //模板数据
	return that
}
func (that *WxApiSendMessageRequest) SetUrl(value string) *WxApiSendMessageRequest {
	that.initParams()
	that.params.Set("url", value) //用户点击后跳转的URL
	return that
}
func (that *WxApiSendMessageRequest) SetMiniAppID(value string) *WxApiSendMessageRequest {
	that.initParams()
	that.params.Set("mini_app_id", value) //所需跳转的小程序appId
	return that
}
func (that *WxApiSendMessageRequest) SetMiniPagePath(value string) *WxApiSendMessageRequest {
	that.initParams()
	that.params.Set("mini_page_path", value) //所需跳转小程序的具体页面路径
	return that
}

//Params ...
func (that *WxApiSendMessageRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	if that.publicParamsSlice != nil {
		for _, _v := range that.publicParamsSlice {
			if _params.Get(_v) == "" {
				return nil, errors.New(that.apiAddress + "缺少参数:" + _v)
			}
		}
	}
	return _params, nil
}

//Do ...
func (that *WxApiSendMessageRequest) Do() (interface{}, error) {
	_data, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		return _data, _err
	}
	return _data, nil
}

//===========================================================================================//

//短信消息推送(阿里大于)
func (that *CooperClient) NewSmsSendMessageRequest() *SmsSendMessageRequest {
	return &SmsSendMessageRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/sms/push",
		},
	}
}

//光明政务云
func (that *CooperClient) NewSmsGmGovRequest() *SmsSendMessageRequest {
	return &SmsSendMessageRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/sms/gmPush",
		},
	}
}

//SmsSendMessageRequest ...
type SmsSendMessageRequest struct {
	Request
}

//SetTempId
func (that *SmsSendMessageRequest) SetTempId(value string) *SmsSendMessageRequest {
	that.initParams()
	that.params.Set("temp_id", value) //短信模板ID
	return that
}

//SetOpenID..
func (that *SmsSendMessageRequest) SetSmsType(value string) *SmsSendMessageRequest {
	that.initParams()
	that.params.Set("sms_type", value) //消息发送方式
	return that
}
func (that *SmsSendMessageRequest) SetSignName(value string) *SmsSendMessageRequest {
	that.initParams()
	that.params.Set("sign_name", value) //短信签名
	return that
}
func (that *SmsSendMessageRequest) SetSmsParams(value string) *SmsSendMessageRequest {
	that.initParams()
	that.params.Set("sms_params", value) //消息模板变量
	return that
}
func (that *SmsSendMessageRequest) SetSmsMobile(value string) *SmsSendMessageRequest {
	that.initParams()
	that.params.Set("sms_mobile", value) //手机号码
	return that
}
func (that *SmsSendMessageRequest) SetSmsCallback(value string) *SmsSendMessageRequest {
	that.initParams()
	that.params.Set("sms_callback", value) //状态回调地址
	return that
}
func (that *SmsSendMessageRequest) SetSmsSendAsync(value string) *SmsSendMessageRequest {
	that.initParams()
	that.params.Set("sms_send_async", value) //消息发送的方式，0同步（默认），1异步
	return that
}
func (that *SmsSendMessageRequest) SetSmsSendType(value int64) *SmsSendMessageRequest {
	that.initParams()
	that.params.Set("send_type", utils.ToString(value)) //消息发送的渠道，11阿里大于（默认），21站内短信，31光明政务云
	return that
}

//Params ...
func (that *SmsSendMessageRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	if that.publicParamsSlice != nil {
		for _, _v := range that.publicParamsSlice {
			if _params.Get(_v) == "" {
				return nil, errors.New(that.apiAddress + "缺少参数:" + _v)
			}
		}
	}
	return _params, nil
}

//Do ...
func (that *SmsSendMessageRequest) Do() (interface{}, error) {
	_data, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		return _data, _err
	}
	return _data, nil
}
