package pposRequest

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

//NewBasePersonnelIdentityGet 获取员工身份列表
func (that *PPOSClient) NewBasePersonnelIdentityGet() *BasePersonnelIdentityGetRequest {
	return &BasePersonnelIdentityGetRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/base/personnel/identityAllList",
		},
	}
}

//BasePersonnelIdentityGetRequest ...
type BasePersonnelIdentityGetRequest struct {
	Request
	IdentityId int64 //身份ID
}

func (that *BasePersonnelIdentityGetRequest) SetIdentityId(value int64) *BasePersonnelIdentityGetRequest {
	that.IdentityId = value
	return that
}

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

//Do ...
func (that *BasePersonnelIdentityGetRequest) Do() ([]*BasePersonnelGetResponse, error) {
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}

	_rs := []*BasePersonnelGetResponse{}
	_sliceData, _ok := _data.(interface{})
	if !_ok {
		return _rs, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	//
	//
	_str, _err := json.Marshal(_sliceData)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + "Umarshal failed!")
	}
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + "Umarshal failed2!")
	}

	return _rs, nil
}
