package pposRequest

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

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

//BasePersonnelGetRequest ...
type BasePersonnelGetRequest struct {
	Request
	PostPersonnelId int64 //员工ID
}

func (that *BasePersonnelGetRequest) SetPostPersonnelId(value int64) *BasePersonnelGetRequest {
	that.PostPersonnelId = value
	return that
}

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

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