/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		unphp <unphp@qq.com>
 * @date		2018-12-18
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package pposRequest

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

//new...
func (that *PPOSClient) NewWxMpMessageSend() *WxMpMessageSendRequest {
	return &WxMpMessageSendRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/wxMp/message/send",
		},
	}
}

//Request...
type WxMpMessageSendRequest struct {
	Request
	CompanyId    int64  `json:"company_id"` //公司ID
	Way          int64  `json:"way"` //发送方式
	TempId       string `json:"temp_id"` //模板ID
	OpenId       string `json:"open_id"` //OpenId
	TempParams   string `json:"temp_params"` //模板变量
	TempMobile   string `json:"temp_mobile"` //手机号
	SignName     string `json:"sign_name"` //签名
	Url          string `json:"url"`
	MiniAppId    string `json:"mini_app_id"`
	MiniPagePath string `json:"mini_page_path"`
}

func (that *WxMpMessageSendRequest) SetCompanyId(value int64) *WxMpMessageSendRequest {
	that.CompanyId = value
	return that
}

func (that *WxMpMessageSendRequest) SetWay(value int64) *WxMpMessageSendRequest {
	that.Way = value
	return that
}

func (that *WxMpMessageSendRequest) SetTempId(value string) *WxMpMessageSendRequest {
	that.TempId = value
	return that
}

func (that *WxMpMessageSendRequest) SetOpenId(value string) *WxMpMessageSendRequest {
	that.OpenId = value
	return that
}

func (that *WxMpMessageSendRequest) SetTempParams(value string) *WxMpMessageSendRequest {
	that.TempParams = value
	return that
}

func (that *WxMpMessageSendRequest) SetTempMobile(value string) *WxMpMessageSendRequest {
	that.TempMobile = value
	return that
}

func (that *WxMpMessageSendRequest) SetSignName(value string) *WxMpMessageSendRequest {
	that.SignName = value
	return that
}

func (that *WxMpMessageSendRequest) SetUrl(value string) *WxMpMessageSendRequest {
	that.Url = value
	return that
}

func (that *WxMpMessageSendRequest) SetMiniAppId(value string) *WxMpMessageSendRequest {
	that.MiniAppId = value
	return that
}

func (that *WxMpMessageSendRequest) SetMiniPagePath(value string) *WxMpMessageSendRequest {
	that.MiniPagePath = value
	return that
}

//Params ...
func (that *WxMpMessageSendRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	if that.CompanyId != 0 {
		_params.Set("company_id", utils.ToString(that.CompanyId))
	}
	if that.Way != 0 {
		_params.Set("way", utils.ToString(that.Way))
	}
	if that.TempId != "" {
		_params.Set("temp_id", that.TempId)
	}
	if that.OpenId != ""  {
		_params.Set("open_id", that.OpenId)
	}
	if that.TempParams != ""  {
		_params.Set("temp_params", that.TempParams)
	}
	if that.TempMobile != ""  {
		_params.Set("temp_mobile", that.TempMobile)
	}
	if that.SignName != ""  {
		_params.Set("sign_name", that.SignName)
	}
	if that.Url != ""  {
		_params.Set("url", that.Url)
	}
	if that.MiniAppId != ""  {
		_params.Set("mini_app_id", that.MiniAppId)
	}
	if that.MiniPagePath != ""  {
		_params.Set("mini_page_path", that.MiniPagePath)
	}
	return _params, nil
}

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