package pposRequest

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

//NewBasePersonnelGet 获取员工详情
func (that *PPOSClient) NewBasePersonnelGetByIds() *PersonnelGetByIdsRequest {
	return &PersonnelGetByIdsRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/base/personnel/getByIds",
		},
	}
}

//PersonnelGetByIdsRequest ...
type PersonnelGetByIdsRequest struct {
	Request
	Ids    string //员工ID
	Column string //员工ID
}

func (that *PersonnelGetByIdsRequest) SetIds(value string) *PersonnelGetByIdsRequest {
	that.Ids = value
	return that
}

//func (that *PersonnelGetByIdsRequest) SetIds(value string) {
//	if value != "" {
//		that.Ids = utils.NewSliceString(strings.Split(value, ",")...).ToInt64()
//	}
//}

//func (that *PersonnelGetByIdsRequest) SetColumn(value string) *PersonnelGetByIdsRequest {
//	that.Column = value
//	return that
//}

//Params ...
func (that *PersonnelGetByIdsRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	_params.Set("ids", utils.ToString(that.Ids))
	//_params.Set("column", utils.ToString(that.Column))
	return _params, nil
}

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