/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		logan <lgq092@163.com>
 * @date		2021-03-16
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package pposRequest

import (
	"errors"
	"net/url"
)

//new...
func (that *PPOSClient) NewStadiumSelect() *StadiumSelectRequest {
	return &StadiumSelectRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/base/stadium/select",
		},
	}
}

//Response...
type StadiumSelectResponse struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

//Request...
type StadiumSelectRequest struct {
	Request
}

//设置商户id
func (that *StadiumSelectRequest) SetId(value string) *StadiumSelectRequest {
	that.initParams()
	that.params.Set("business_id", value)
	return that
}

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

//Do ...
func (that *StadiumSelectRequest) Do() ([]*StadiumSelectResponse, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_sliceData, _ok := _data.([]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	_rs := []*StadiumSelectResponse{}
	for _, _v := range _sliceData {
		_vData, _ok := _v.(map[string]interface{})
		if !_ok {
			return nil, errors.New(that.apiAddress + "请求响应格式不正确2")
		}
		_tmp := new(StadiumSelectResponse)
		if _err := that.ParseResponeMp(_tmp, _vData, false); _err != nil {
			return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
		}
		_rs = append(_rs, _tmp)
	}
	return _rs, nil
}
