package pposRequest

import (
	"errors"
	"net/url"
)

//NewClassStudentGetMemberInfoRequest 课程业务通过订单号获取客户信息
func (that *PPOSClient) NewClassStudentGetMemberInfoRequest() *ClassStudentGetMemberInfoRequest {
	return &ClassStudentGetMemberInfoRequest{
		Request: Request{
			Client: that,
			publicParamsSlice: []string{
				"parent_order_no",
			},
			apiAddress: "/class/student/getMemberInfo",
		},
	}
}

//ClassStudentGetMemberInfoRequest ...
type ClassStudentGetMemberInfoRequest struct {
	Request
}

func (that *ClassStudentGetMemberInfoRequest) SetParentOrderNo(value string) *ClassStudentGetMemberInfoRequest {
	that.initParams()
	that.params.Set("parent_order_no", value)
	return that
}

//Params ...
func (that *ClassStudentGetMemberInfoRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	if that.publicParamsSlice != nil {
		for _, _v := range that.publicParamsSlice {
			if _params.Get(_v) == "" {
				return nil, errors.New(that.apiAddress + "缺少参数:" + _v)
			}
		}
	}
	return _params, nil
}

//Do ...
func (that *ClassStudentGetMemberInfoRequest) Do() (map[string]interface{}, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	_response, _ok := _data.(map[string]interface{})
	if !_ok {
		return nil, errors.New("数据格式错误")
	}
	return _response, nil
}
