package pposRequest

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

//NewAcSysOptionRequest 获取公司列表
func (that *PPOSClient) NewAcSysOptionRequest() *AcSysOptionRequest {
	return &AcSysOptionRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/base/sysOption/list",
		},
	}
}

//AcSysOptionRequest ...
type AcSysOptionRequest struct {
	Request
	Type int64 `param:"<in:formData> <default:1><desc:类型,1:项目名称,2:时长,3:可销售渠道> <range: 1:100000>"`
}

func (that *AcSysOptionRequest) SetType(value int64) *AcSysOptionRequest {
	that.Type = value
	return that
}

//Params ...
func (that *AcSysOptionRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	_params.Set("type", utils.ToString(that.Type))
	return _params, nil
}

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