package pposRequest

import (
	"encoding/json"
	"errors"
	"net/url"
)

//new... 公司新增时初始化短信账户
func (that *PPOSClient) NewMcCompanySmsAmountRequest() *McCompanySmsAmountRequest {
	return &McCompanySmsAmountRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/mc/admin/smsAccountAdd",
			publicParamsSlice: []string{
				"",
			},
		},
	}
}

//Response...
type McCompanySmsAmountResponse struct {
	SmsAccountId int64  `json:"sms_account_id"`
	CompanyId    int64  `json:"company_id"`
	SmsCount     int64  `json:"sms_count"`
	AccountName  string `json:"account_name"`
	Desc         string `json:"desc"`
}

//Request...
type McCompanySmsAmountRequest struct {
	Request
}

func (that *McCompanySmsAmountRequest) SetAccountName(value string) *McCompanySmsAmountRequest {
	that.initParams()
	that.params.Set("account_name", value) //名称
	return that
}

func (that *McCompanySmsAmountRequest) SetDesc(value string) *McCompanySmsAmountRequest {
	that.initParams()
	that.params.Set("desc", value) //描述
	return that
}

//Params ...
func (that *McCompanySmsAmountRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	return _params, nil
}

//Do ...
func (that *McCompanySmsAmountRequest) Do() (*McCompanySmsAmountResponse, 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 + "请求响应格式不正确")
	}
	//
	_str, _err := json.Marshal(_sliceData)
	if _err != nil {
		return nil, errors.New(that.apiAddress + "Umarshal failed!" + _err.Error())
	}
	_rs := new(McCompanySmsAmountResponse)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return nil, errors.New(that.apiAddress + "Umarshal failed2!" + _err.Error())
	}
	return _rs, nil
}
