package warehouse_createFence_request

import (
	"encoding/json"
	warehouse_createFence_response "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/warehouse_createFence/response"
	doudian_sdk "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/core"
)

type WarehouseCreateFenceRequest struct {
	doudian_sdk.BaseDoudianOpApiRequest
	Param *WarehouseCreateFenceParam
}

func (c *WarehouseCreateFenceRequest) GetUrlPath() string {
	return "/warehouse/createFence"
}

func New() *WarehouseCreateFenceRequest {
	request := &WarehouseCreateFenceRequest{
		Param: &WarehouseCreateFenceParam{},
	}
	request.SetConfig(doudian_sdk.GlobalConfig)
	request.SetClient(doudian_sdk.DefaultDoudianOpApiClient)
	return request

}

func (c *WarehouseCreateFenceRequest) Execute(accessToken *doudian_sdk.AccessToken) (*warehouse_createFence_response.WarehouseCreateFenceResponse, error) {
	responseJson, err := c.GetClient().Request(c, accessToken)
	if err != nil {
		return nil, err
	}
	response := &warehouse_createFence_response.WarehouseCreateFenceResponse{}
	_ = json.Unmarshal([]byte(responseJson), response)
	return response, nil

}

func (c *WarehouseCreateFenceRequest) GetParamObject() interface{} {
	return c.Param
}

func (c *WarehouseCreateFenceRequest) GetParams() *WarehouseCreateFenceParam {
	return c.Param
}

type WarehouseCreateFenceParam struct {
	// 围栏信息
	FenceInfo *FenceInfo `json:"fence_info"`
}
type Center struct {
	// 经度
	Longitude float64 `json:"longitude"`
	// 纬度
	Latitude float64 `json:"latitude"`
}
type VerticesItem struct {
	// 经度
	Longitude float64 `json:"longitude"`
	// 纬度
	Latitude float64 `json:"latitude"`
}
type Outer struct {
	// 经纬度列表，外圈为逆时针
	Vertices []VerticesItem `json:"vertices"`
}
type PolygonNew struct {
	// 带洞多边形的外圈数据
	Outer *Outer `json:"outer"`
	// 带洞多边形的内圈数据，空表示普通多边形
	Inner []InnerItem `json:"inner"`
}
type MultiPolygonsItem struct {
	// 带洞多边形的外圈数据
	Outer *Outer `json:"outer"`
	// 带洞多边形的内圈数据，空表示普通多边形
	Inner []InnerItem `json:"inner"`
}
type FenceInfo struct {
	// 外部围栏id，必传
	OutFenceId string `json:"out_fence_id"`
	// 形状 1. 圆 使用circular 2:多边形，使用polygon  3:带洞多边形（兼容普通多边形），使用polygon_new  4:多个多边形，兼容带洞和不带洞，使用multi_polygons
	Shape int32 `json:"shape"`
	// 形状为圆的经纬度信息，对应shape=1
	Circular *Circular `json:"circular"`
	// 普通多边形 ，对应shape=2
	Polygon *Polygon `json:"polygon"`
	// 带洞多边形，可兼容普通多边形 ，对应shape=3
	PolygonNew *PolygonNew `json:"polygon_new"`
	// 多个多边形 ，对应shape=4
	MultiPolygons []MultiPolygonsItem `json:"multi_polygons"`
}
type Circular struct {
	// 圆的中心经纬度
	Center *Center `json:"center"`
	// 半径，单位 米
	Radius float64 `json:"radius"`
}
type Polygon struct {
	// 多边形顶点的经纬度：逆时针
	Vertices []VerticesItem `json:"vertices"`
}
type InnerItem struct {
	// 经纬度列表，内圈为顺时针
	Vertices []VerticesItem `json:"vertices"`
}
