package sku_syncStockBatch_request

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

type SkuSyncStockBatchRequest struct {
	doudian_sdk.BaseDoudianOpApiRequest
	Param *SkuSyncStockBatchParam
}

func (c *SkuSyncStockBatchRequest) GetUrlPath() string {
	return "/sku/syncStockBatch"
}

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

}

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

}

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

func (c *SkuSyncStockBatchRequest) GetParams() *SkuSyncStockBatchParam {
	return c.Param
}

type StockMapItem struct {
	// 仓id，超市小时达子品传storeId
	OutWarehouseId string `json:"out_warehouse_id"`
	// 库存数量
	StockNum int64 `json:"stock_num"`
}
type SkuSyncListItem struct {
	// skuid
	SkuId int64 `json:"sku_id"`
	// 库存类型：0普通库存，1区域库存,10阶梯库存。 超市小时达子品传区域库存
	SkuType int64 `json:"sku_type"`
	// 普通库存数量
	StockNum int64 `json:"stock_num"`
	// 阶梯库存数量
	StepStockNum int64 `json:"step_stock_num"`
	// 区域库存配置
	StockMap []StockMapItem `json:"stock_map"`
	// 供应商ID
	SupplierId string `json:"supplier_id"`
}
type SkuSyncStockBatchParam struct {
	// 商品ID，整型格式
	ProductId int64 `json:"product_id"`
	// 幂等ID，仅incremental=true时有用
	IdempotentId string `json:"idempotent_id"`
	// true表示增量库存，false表示全量库存，默认为false
	Incremental bool `json:"incremental"`
	// 需要批量提交的skuid及对应的库存和仓
	SkuSyncList []SkuSyncListItem `json:"sku_sync_list"`
}
