package product_detail_request_out

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

type ProductDetailOutRequest struct {
	doudian_sdk.BaseDoudianOpApiRequest
	Param *ProductDetailParamOutProductId
}

func (c *ProductDetailOutRequest) GetUrlPath() string {
	return "/product/detail"
}

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

}

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

}

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

func (c *ProductDetailOutRequest) GetParams() *ProductDetailParamOutProductId {
	return c.Param
}

type ProductDetailParamOutProductId struct {
	// 商品ID，抖店系统生成，店铺下唯一；长度19位。
	ProductId string `json:"product_id"`
	// 外部商家编码，商家自定义字段
	OutProductId string `json:"out_product_id"`
	// 门店id
	StoreId int64 `json:"store_id"`
	//// true：读取草稿数据；false：读取线上数据；不传默认为false
	//ShowDraft string `json:"show_draft"`
}
