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

package pposRequest

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

//new...
func (that *PPOSClient) NewSyncPassengerByCamera() *SyncPassengerByCameraRequest {
	return &SyncPassengerByCameraRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/platform/openData/passengerByCamera",
		},
	}
}

func (that *PPOSClient) NewSyncBasePassengerByCamera() *SyncPassengerByCameraRequest {
	_client := &SyncPassengerByCameraRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/statistic/ruiweiRequest/pull",
		},
	}
	_client.initParams()
	_client.params.Set("user_name", that.appId)
	_client.params.Set("password", that.apiKey)
	return _client
}

//Request...
type SyncPassengerByCameraRequest struct {
	Request
}

func (that *SyncPassengerByCameraRequest) SetPage(value int64) *SyncPassengerByCameraRequest {
	that.initParams()
	that.params.Set("page", utils.ToString(value)) //页码
	return that
}
func (that *SyncPassengerByCameraRequest) SetSize(value int64) *SyncPassengerByCameraRequest {
	that.initParams()
	that.params.Set("size", utils.ToString(value)) //每页条数
	return that
}
func (that *SyncPassengerByCameraRequest) SetDate(value string) *SyncPassengerByCameraRequest {
	that.initParams()
	that.params.Set("date", value) //采集时间
	return that
}

//Params ...
func (that *SyncPassengerByCameraRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	return _params, nil
}

type SyncPassengerByCameraResponse struct {
	Count int64      `json:"count"` //count
	List  []utils.Mp `json:"list"`  //list
	Page  int64      `json:"page"`  //page
	Size  int64      `json:"size"`  //size
}

//Do ...
func (that *SyncPassengerByCameraRequest) Do() ([]utils.Mp, error) {
	//_rs := SyncPassengerByCameraResponse{}
	_rs := make([]utils.Mp, 0)
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return _rs, _err
	}
	//
	//_slice := []string{
	//	"count",
	//	"list",
	//	"page",
	//	"size",
	//}
	//_sliceData, _ok := _data.(map[string]interface{})
	//if !_ok {
	//	return _rs, errors.New(that.apiAddress + "请求响应格式不正确")
	//}
	//for _, _val := range _slice {
	//	if _, _ok := _sliceData[_val]; !_ok {
	//		return _rs, errors.New(that.apiAddress + "请求响应参数不正确2")
	//	}
	//}
	//
	_str, _err := json.Marshal(_data)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	fmt.Println("++++++data++++++", string(_str))
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	return _rs, nil
}
