/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		tang <unphp@qq.com>
 * @date		2021-03-03
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */
package cooper

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

//NewFaceSrcListAllRequest ... 人脸库列表
func (that *CooperClient) NewFaceSrcListAllRequest() *FaceSrcListAllRequest {
	return &FaceSrcListAllRequest{
		Request: Request{
			Client:            that,
			publicParamsSlice: []string{
				//...
			},
			apiAddress: "/baiduFace/srcListAll",
		},
	}
}

//FaceSrcListAllRequest
type FaceSrcListAllRequest struct {
	Request
}

func (that *FaceSrcListAllRequest) SetGroupID(value string) *FaceSrcListAllRequest {
	that.initParams()
	that.params.Set("group_id", value) //组
	return that
}
func (that *FaceSrcListAllRequest) SetUserIds(value string) *FaceSrcListAllRequest {
	that.initParams()
	that.params.Set("user_ids", value)
	return that
}
func (that *FaceSrcListAllRequest) SetPage(value string) *FaceSrcListAllRequest {
	that.initParams()
	that.params.Set("page", value) //页码
	return that
}
func (that *FaceSrcListAllRequest) SetSize(value string) *FaceSrcListAllRequest {
	that.initParams()
	that.params.Set("size", value) //条数
	return that
}
func (that *FaceSrcListAllRequest) SetDeviceId(value string) *FaceSrcListAllRequest {
	that.initParams()
	that.params.Set("device_id", value) //设备ID
	return that
}
func (that *FaceSrcListAllRequest) SetStartDate(value string) *FaceSrcListAllRequest {
	that.initParams()
	that.params.Set("start_date", value)
	return that
}
func (that *FaceSrcListAllRequest) SetEndDate(value string) *FaceSrcListAllRequest {
	that.initParams()
	that.params.Set("end_date", value)
	return that
}

//Params ...
func (that *FaceSrcListAllRequest) 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
}

//响应体
type FaceSrcListAllResponse struct {
	Count int64                      `json:"count"`
	List  []*FaceSrcDeviceListStruct `json:"list"`
	Page  int64                      `json:"page"`
	Size  int64                      `json:"size"`
}

type FaceSrcDeviceListStruct struct {
	CTime      int64    `json:"c_time"`
	DeviceInfo []string `json:"device_info"`
	FaceSrc    string   `json:"face_src"`
	FaceStatus int64    `json:"face_status"`
	GroupId    int64    `json:"group_id"`
	UserId     int64    `json:"user_id"`
}

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