package ability589

import (
	"errors"
	"git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk"
	request2 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability589/request"
	response2 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability589/response"
	"git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/util"
	"log"
)

type Ability589 struct {
	Client *topsdk.TopClient
}

func NewAbility589(client *topsdk.TopClient) *Ability589 {
	return &Ability589{client}
}

/*
   五道口库存发布接口（针对外部渠道）
*/
func (ability *Ability589) AlibabaWdkStockPublish(req *request2.AlibabaWdkStockPublishRequest) (*response2.AlibabaWdkStockPublishResponse, error) {
	if ability.Client == nil {
		return nil, errors.New("Ability589 topClient is nil")
	}
	var jsonStr, err = ability.Client.Execute("alibaba.wdk.stock.publish", req.ToMap(), req.ToFileMap())
	var respStruct = response2.AlibabaWdkStockPublishResponse{}
	if err != nil {
		log.Println("alibabaWdkStockPublish error", err)
		return &respStruct, err
	}
	err = util.HandleJsonResponse(jsonStr, &respStruct)
	if respStruct.Body == "" || len(respStruct.Body) == 0 {
		respStruct.Body = jsonStr
	}
	return &respStruct, err
}

/*
   初始化覆盖实物库存
*/
func (ability *Ability589) AlibabaWdkUmsInventoryPublish(req *request2.AlibabaWdkUmsInventoryPublishRequest, session string) (*response2.AlibabaWdkUmsInventoryPublishResponse, error) {
	if ability.Client == nil {
		return nil, errors.New("Ability589 topClient is nil")
	}
	var jsonStr, err = ability.Client.ExecuteWithSession("alibaba.wdk.ums.inventory.publish", req.ToMap(), req.ToFileMap(), session)
	var respStruct = response2.AlibabaWdkUmsInventoryPublishResponse{}
	if err != nil {
		log.Println("alibabaWdkUmsInventoryPublish error", err)
		return &respStruct, err
	}
	err = util.HandleJsonResponse(jsonStr, &respStruct)
	if respStruct.Body == "" || len(respStruct.Body) == 0 {
		respStruct.Body = jsonStr
	}
	return &respStruct, err
}
