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

package pposRequest

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

//new...
func (that *PPOSClient) NewSyncDeviceByStadium() *SyncDeviceByStadiumRequest {
	return &SyncDeviceByStadiumRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/platform/openData/passengerEyeGet",
		},
	}
}

//Request...
type SyncDeviceByStadiumRequest struct {
	Request
}

func (that *SyncDeviceByStadiumRequest) SetPage(value int64) *SyncDeviceByStadiumRequest {
	that.initParams()
	that.params.Set("page", utils.ToString(value)) //页码
	return that
}
func (that *SyncDeviceByStadiumRequest) SetSize(value int64) *SyncDeviceByStadiumRequest {
	that.initParams()
	that.params.Set("size", utils.ToString(value)) //每页条数
	return that
}

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

type SyncDeviceByStadiumResponse struct {
	EquipmentName  string `json:"equipment_name"`   //设备的名称
	Location       string `json:"location"`         //设备的具体位置
	IpAddress      string `json:"ip_address"`       //实时视频预览的参数，根据品牌不同(海康：设备唯一串码。宇视：设备通道号。)
	BrandId        string `json:"brand_id"`         //品牌对应的数字.(海康，大华，宇视，...)
	TypeId         int64  `json:"type_id"`          //类型对应的数字.(1为摄像机，2为录像机)
	IsCoreArea     int64  `json:"is_core_area"`     //是否核心免低区域:1是2不是
	IsEarlyWarning int64  `json:"is_early_warning"` //是否预警:1是2不是
	MacAddress     string `json:"mac_address"`      //mac地址
}

//Do ...
func (that *SyncDeviceByStadiumRequest) Do() ([]*SyncDeviceByStadiumResponse, error) {
	_rs := make([]*SyncDeviceByStadiumResponse, 0)
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return _rs, _err
	}
	_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 + _err.Error())
	}
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	return _rs, nil
}
