package product_createComponentTemplateV2_request

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

type ProductCreateComponentTemplateV2Request struct {
	doudian_sdk.BaseDoudianOpApiRequest
	Param *ProductCreateComponentTemplateV2Param
}

func (c *ProductCreateComponentTemplateV2Request) GetUrlPath() string {
	return "/product/createComponentTemplateV2"
}

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

}

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

}

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

func (c *ProductCreateComponentTemplateV2Request) GetParams() *ProductCreateComponentTemplateV2Param {
	return c.Param
}

type ProductCreateComponentTemplateV2Param struct {
	// 模板类型：尺码模板
	TemplateType string `json:"template_type"`
	// 模板子类型: clothing(服装)、undies(内衣)、shoes(鞋靴类)、children_clothing(童装)
	TemplateSubType string `json:"template_sub_type"`
	// 模板名称
	TemplateName string `json:"template_name"`
	// 商品组件数据 json，表格行列顺序以selectedSize和selectedSpecs的顺序为准
	ComponentFrontData string `json:"component_front_data"`
	// 是否为公有模板(多个商品可共用)
	Shareable bool `json:"shareable"`
	// 类目id，用来确定模板类型
	CategoryId int64 `json:"category_id"`
}
