package material_uploadImageSync_request

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

type MaterialUploadImageSyncRequest struct {
	doudian_sdk.BaseDoudianOpApiRequest
	Param *MaterialUploadImageSyncParam
}

func (c *MaterialUploadImageSyncRequest) GetUrlPath() string {
	return "/material/uploadImageSync"
}

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

}

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

}

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

func (c *MaterialUploadImageSyncRequest) GetParams() *MaterialUploadImageSyncParam {
	return c.Param
}

type MaterialUploadImageSyncParam struct {
	// 文件夹id，可使用【/material/createFolder】接口创建获取文件夹id
	FolderId string `json:"folder_id"`
	// 图片url，必须是公网可访问
	Url string `json:"url"`
	// 图片名称，开发者自定义，不得超过50个字符。请求成功后图片在抖店素材中心可以查看。
	MaterialName string `json:"material_name"`
	// 是否唯一存储，true-同一张图片素材中心只会存储一份，接口会正常响应请求成功;false-新增一张图片至素材中心；不传默认false；
	NeedDistinct bool `json:"need_distinct"`
	// 请求的唯一标识符，有效时间为1个小时，即：一个小时内使用同样的request_id，视为同一请求。如果未传该参数，素材中心将使用url+material_name生成request_id；接口会正常响应请求成功
	RequestId string `json:"request_id"`
}
