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

package pposRequest

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

//new...
func (that *PPOSClient) NewContestManageList() *ContestManageListRequest {
	return &ContestManageListRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/events/contestManage/byBusinessIds",
		},
	}
}

type ContestManageListResponse struct {
	BusinessId int64  `json:"business_id"`
	ManageId   int64  `json:"manage_id"`
	ManageName string `json:"manage_name"`
}

//Request...
type ContestManageListRequest struct {
	Request
}

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

//设置类型 1场馆 2团队
func (that *ContestManageListRequest) SetKind(value string) *ContestManageListRequest {
	that.initParams()
	that.params.Set("kind", value)
	return that
}

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

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

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

//Do ...
func (that *ContestManageListRequest) Do() ([]*ContestManageListResponse, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}

	_str, _err := json.Marshal(_data)
	//返回结果
	_rs := make([]*ContestManageListResponse, 0)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	return _rs, nil
}
