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

package pposRequest

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

//new...
func (that *PPOSClient) NewSyncDeviceSentryByStadium() *SyncDeviceSentryByStadiumRequest {
	return &SyncDeviceSentryByStadiumRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/platform/openData/passengerSentryList",
		},
	}
}

//Request...
type SyncDeviceSentryByStadiumRequest struct {
	Request
}

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

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

type SyncDeviceSentryByStadiumResponse struct {
	SentryId            int64  `json:"sentry_id"`              //设备id
	DeviceNo            string `json:"device_no"`              //设备序列号
	DeviceName          string `json:"device_name"`            //设备名称
	MacAddress          string `json:"mac_address"`            //设备名称
	M3u8VideoUrl        string `json:"m3u8_video_url"`         //M3u8播放地址
	M3u8HistoryVideoUrl string `json:"m3u8_history_video_url"` //M3u8历史播放地址
	PositionName        string `json:"position_name"`          //具体位置
	BrandId             string `json:"brand_id"`               //品牌对应的数字.(海康，大华，宇视，...)
	TypeId              int64  `json:"type_id"`                //类型对应的数字.(1为摄像机，2为录像机)
	IsCoreArea          int64  `json:"is_core_area"`           //是否核心免低区域:1是2不是
}

//Do ...
func (that *SyncDeviceSentryByStadiumRequest) Do() ([]*SyncDeviceSentryByStadiumResponse, error) {
	_rs := make([]*SyncDeviceSentryByStadiumResponse, 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
}
