package pposRequest

import (
	"errors"
	"net/url"
)

//NewAisleListGetByAccessDevice 获取通道
func (that *PPOSClient) NewAisleListGetByAccessDevice() *AisleListGetByAccessDeviceRequest {
	return &AisleListGetByAccessDeviceRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/enterAdmin/aisleList/getByAccessDevice",
		},
	}
}

//AisleListGetByAccessDeviceRequest 获取通道
type AisleListGetByAccessDeviceRequest struct {
	Request
	AccessDevice string `json:"access_device"` //设备id
}

func (that *AisleListGetByAccessDeviceRequest) SetAccessDevice(accessDevice string) *AisleListGetByAccessDeviceRequest {
	that.AccessDevice = accessDevice
	return that
}


//Params ...
func (that *AisleListGetByAccessDeviceRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	_params.Set("access_device", that.AccessDevice)
	return _params, nil
}

//Do ...
func (that *AisleListGetByAccessDeviceRequest) Do() ([]*AisleListGetByAccessResponse, error) {
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	_rs := []*AisleListGetByAccessResponse{}
	_sliceData, _ok := _data.([]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(AisleListGetByAccessResponse)
		if _err := that.ParseResponeMp(_tmp, _vData); _err != nil {
			return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
		}
		_rs = append(_rs, _tmp)
	}
	return _rs, nil
}
