package material_batchUploadImageSync_request

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

type MaterialBatchUploadImageSyncRequest struct {
	doudian_sdk.BaseDoudianOpApiRequest
	Param *MaterialBatchUploadImageSyncParam
}

func (c *MaterialBatchUploadImageSyncRequest) GetUrlPath() string {
	return "/material/batchUploadImageSync"
}

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

}

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

}

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

func (c *MaterialBatchUploadImageSyncRequest) GetParams() *MaterialBatchUploadImageSyncParam {
	return c.Param
}

type MaterialsItem struct {
	// 素材的唯一id，用于接口幂等（限时1个小时）
	RequestId string `json:"request_id"`
	// 文件夹id，“0”表示将素材上传到素材中心根目录
	FolderId string `json:"folder_id"`
	// 固定值photo
	MaterialType string `json:"material_type"`
	// 素材名称，长度限制为50个字符
	Name string `json:"name"`
	// 素材url，素材中心会将改url转换成素材中心的url
	Url string `json:"url"`
}
type MaterialBatchUploadImageSyncParam struct {
	// 素材信息
	Materials []MaterialsItem `json:"materials"`
	// 是否唯一存储，如果为true，同一张图片素材中心只会存储一份
	NeedDistinct bool `json:"need_distinct"`
}
