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

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

//NewFaceSrcListRequest ... 人脸下发记录
func (that *CooperClient) NewFaceSrcListRequest() *FaceSrcListRequest {
	return &FaceSrcListRequest{
		Request: Request{
			Client:            that,
			publicParamsSlice: []string{
				//...
			},
			apiAddress: "/baiduFace/srcList",
		},
	}
}

//FaceSrcListRequest
type FaceSrcListRequest struct {
	Request
}

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

//Params ...
func (that *FaceSrcListRequest) 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 FaceSrcListResponse struct {
	Count int64                `json:"count"`
	List  []*FaceSrcListStruct `json:"list"`
	Page  int64                `json:"page"`
	Size  int64                `json:"size"`
}

type FaceSrcListStruct struct {
	CTime      int64  `json:"c_time"`
	SyncStatus int64  `json:"sync_status"`
	FaceStatus int64  `json:"face_status"`
	GroupId    int64  `json:"group_id"`
	UserId     int64  `json:"user_id"`
	FaceSrc    string `json:"face_src"`
}

//Do ...
func (that *FaceSrcListRequest) Do() (*FaceSrcListResponse, 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(FaceSrcListResponse)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + "Umarshal failed2!" + _err.Error())
	}
	return _rs, nil
}
