package pposRequest

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

//new...
func (that *PPOSClient) NewCompanyGetByStoreIdRequest() *CompanyGetByStoreIdRequest {
	return &CompanyGetByStoreIdRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/base/company/getByStoreId",
			publicParamsSlice: []string{
				"store_id",
			},
		},
	}
}

//Response...
type CompanyGetByStoreIdResponse struct {
	CompanyId  int64  `json:"company_id"`
	BusinessId int64  `json:"business_id"`
	StadiumId  int64  `json:"stadium_id"`
	SmsChannel int64  `json:"sms_channel"`
	SmsSign    string `json:"sms_sign"`
}

//Request...
type CompanyGetByStoreIdRequest struct {
	Request
}

func (that *CompanyGetByStoreIdRequest) SetStoreId(value string) *CompanyGetByStoreIdRequest {
	that.initParams()
	that.params.Set("store_id", value)
	return that
}

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

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