package warehouse_create_request

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

type WarehouseCreateRequest struct {
	doudian_sdk.BaseDoudianOpApiRequest
	Param *WarehouseCreateParam
}

func (c *WarehouseCreateRequest) GetUrlPath() string {
	return "/warehouse/createV2"
}

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

}

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

}

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

func (c *WarehouseCreateRequest) GetParams() *WarehouseCreateParam {
	return c.Param
}

type WarehouseLocation struct {
	// 省地址编码
	AddressId1 int64 `json:"address_id1"`
	// 市地址编码
	AddressId2 int64 `json:"address_id2"`
	// 区地址编码
	AddressId3 int64 `json:"address_id3"`
	// 街道地址编码
	AddressId4 int64 `json:"address_id4"`
}
type WarehouseCreateParam struct {
	// 外部仓库ID，一个店铺下，同一个外部ID只能创建一个仓库
	OutWarehouseId string `json:"out_warehouse_id"`
	// 仓库名称
	Name string `json:"name"`
	// 仓库介绍
	Intro string `json:"intro"`
	//仓信息
	Warehouse *Warehouse `json:"warehouse"`
}
type Warehouse struct {
	// 仓地址编码  苹果门店店铺、超市小时达店铺建仓必传
	WarehouseLocation *WarehouseLocation `json:"warehouse_location"`
	// 仓地址详细地址，苹果门店店铺、超市小时达店铺建仓必传
	AddressDetail string `json:"address_detail"`
}
