package pposRequest

import (
	"PPOSUtils/utils"
	"encoding/json"
	"net/url"
)

//NewPersonnelBusinessList 获取中心员工
func (that *PPOSClient) NewPersonnelBusinessList() *PersonnelBusinessListRequest {
	return &PersonnelBusinessListRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/base/personnel/businessList",
		},
	}
}

//PersonnelBusinessListRequest ...
type PersonnelBusinessListRequest struct {
	Request
	Status int64 //状态
	Page   int64 //页码
	Size   int64 //每页条数
	Keyword string
}

func (that *PersonnelBusinessListRequest) SetStatus(value int64) *PersonnelBusinessListRequest {
	that.Status = value
	return that
}

func (that *PersonnelBusinessListRequest) SetPage(value int64) *PersonnelBusinessListRequest {
	that.Page = value
	return that
}

func (that *PersonnelBusinessListRequest) SetSize(value int64) *PersonnelBusinessListRequest {
	that.Size = value
	return that
}

func (that *PersonnelBusinessListRequest) SetKeyword(value string) *PersonnelBusinessListRequest {
	that.Keyword = value
	return that
}


//Params ...
func (that *PersonnelBusinessListRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	_params.Set("status", utils.ToString(that.Status))
	_params.Set("page", utils.ToString(that.Page))
	_params.Set("size", utils.ToString(that.Size))
	_params.Set("keyword", that.Keyword)
	return _params, nil
}

//Do ...
func (that *PersonnelBusinessListRequest) Do() ([]*PersonnelListResponse, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//返回结果
	_rs := new(PersonnelBusinessListResponse)
	_byte, _err := json.Marshal(_data)
	if _err != nil {
		return nil, _err
	}
	_err = json.Unmarshal(_byte, _rs)
	if _err != nil {
		return nil, _err
	}
	return _rs.List, nil
}
