package superm_product_createSubProduct_request

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

type SupermProductCreateSubProductRequest struct {
	doudian_sdk.BaseDoudianOpApiRequest
	Param *SupermProductCreateSubProductParam
}

func (c *SupermProductCreateSubProductRequest) GetUrlPath() string {
	return "/superm/product/createSubProduct"
}

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

}

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

}

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

func (c *SupermProductCreateSubProductRequest) GetParams() *SupermProductCreateSubProductParam {
	return c.Param
}

type SkuInfoItem struct {
	// 子商品规格值列表
	SellPropertyNames []string `json:"sell_property_names"`
	// 子商品SKU价格 (单位：分)
	Price int64 `json:"price"`
	// 子商品SKU库存
	Stock int64 `json:"stock"`
}
type SupermProductCreateSubProductParam struct {
	// 店铺主商品ID
	MainProductId int64 `json:"main_product_id"`
	// 门店ID
	StoreId int64 `json:"store_id"`
	// 子商品SKU的库存、价格信息
	SkuInfo []SkuInfoItem `json:"sku_info"`
}
