package pposRequest

import (
	"PPOSUtils/utils"
	"errors"
	"net/url"
)

//NewAisleList 获取通道
func (that *PPOSClient) NewAisleList() *AisleListRequest {
	return &AisleListRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/enterAdmin/aisleList/list",
		},
	}
}

//AisleListRequest 获取通道
type AisleListRequest struct {
	Request
	StadiumId int64 `json:"stadium_id"` //场馆id
}

func (that *AisleListRequest) SetCompanyId(CompanyId int64) *AisleListRequest {
	that.initParams()
	that.params.Set("company_id", utils.ToString(CompanyId))
	return that
}

func (that *AisleListRequest) SetBusinessId(BusinessId int64) *AisleListRequest {
	that.initParams()
	that.params.Set("business_id", utils.ToString(BusinessId))
	return that
}

func (that *AisleListRequest) SetStadiumId(StadiumId int64) *AisleListRequest {
	that.initParams()
	that.params.Set("stadium_id", utils.ToString(StadiumId))
	return that
}

func (that *AisleListRequest) SetPage(page int64) *AisleListRequest {
	that.initParams()
	that.params.Set("page", utils.ToString(page))
	return that
}

func (that *AisleListRequest) SetSize(size int64) *AisleListRequest {
	that.initParams()
	that.params.Set("size", utils.ToString(size))
	return that
}

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

//Do ...
func (that *AisleListRequest) Do() ([]*AisleListResponse, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	var _list interface{}
	_listData, _err := that.ParseByList(_data)
	if _err != nil {
		return nil, _err
	}
	_list = _listData.List
	//返回结果
	_rs := []*AisleListResponse{}
	_sliceData, _ok := _list.([]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	for _, _v := range _sliceData {
		_vData, _ok := _v.(map[string]interface{})
		if !_ok {
			return nil, errors.New(that.apiAddress + "请求响应格式不正确2")
		}
		_tmp := new(AisleListResponse)
		if _err := that.ParseResponeMp(_tmp, _vData); _err != nil {
			return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
		}
		_rs = append(_rs, _tmp)
	}
	return _rs, nil
}
