package pposRequest

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

//new...
func (that *PPOSClient) NewCompanyGetByIdRequest() *CompanyGetByIdRequest {
	return &CompanyGetByIdRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/base/company/get",
			publicParamsSlice: []string{
				"",
			},
		},
	}
}

//Response...
type CompanyGetByIdResponse struct {
	CompanyId       int64  `json:"company_id"`
	CompanyName     string `json:"company_name"`
	Domain          string `json:"domain"`
	WxDomain        string `json:"wx_domain"`
	SmsChannel      int64  `json:"sms_channel"`
	AuthPaymentType string `json:"auth_payment_type"`
	SmsSign         string `json:"sms_sign"`
}

//Request...
type CompanyGetByIdRequest struct {
	Request
}

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

//Do ...
func (that *CompanyGetByIdRequest) Do() (*CompanyGetByIdResponse, 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!")
	}
	_rs := new(CompanyGetByIdResponse)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return nil, errors.New(that.apiAddress + "Umarshal failed2!")
	}
	return _rs, nil
}
