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

package pposRequest

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

//new...
func (that *PPOSClient) NewStadiumValidList() *StadiumValidListRequest {
	return &StadiumValidListRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/base/stadium/validList",
		},
	}
}

//Response...
type StadiumValidListResponse struct {
	Count int64              `json:"count"` //count
	List  []StadiumValidList `json:"list"`  //list
	Page  int64              `json:"page"`  //page
	Size  int64              `json:"size"`  //size
}

type StadiumValidList struct {
	BusinessId  int64  `json:"business_id"`
	StadiumId   int64  `json:"stadium_id"`
	StadiumName string `json:"stadium_name"`
}

//Request...
type StadiumValidListRequest struct {
	Request
}

//设置商户ids
func (that *StadiumValidListRequest) SetBusinessIds(value string) *StadiumValidListRequest {
	that.initParams()
	that.params.Set("business_ids", value)
	return that
}

//设置类型 1场馆 2商户联盟
func (that *StadiumValidListRequest) SetKind(value string) *StadiumValidListRequest {
	that.initParams()
	that.params.Set("kind", value)
	return that
}

//
func (that *StadiumValidListRequest) SetPage(value string) *StadiumValidListRequest {
	that.initParams()
	that.params.Set("page", value)
	return that
}

//
func (that *StadiumValidListRequest) SetSize(value string) *StadiumValidListRequest {
	that.initParams()
	that.params.Set("size", value)
	return that
}

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

//Do ...
func (that *StadiumValidListRequest) Do() (StadiumValidListResponse, error) {
	_rs := StadiumValidListResponse{}
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return _rs, _err
	}
	//
	_slice := []string{
		"count",
		"list",
		"page",
		"size",
	}
	//
	_sliceData, _ok := _data.(map[string]interface{})
	if !_ok {
		return _rs, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	//
	for _, _val := range _slice {
		if _, _ok := _sliceData[_val]; !_ok {
			return _rs, errors.New(that.apiAddress + "请求响应参数不正确2")
		}
	}
	//
	_str, _err := json.Marshal(_sliceData)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	return _rs, nil
}
