package ability1475

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

type Ability1475 struct {
	Client *topsdk.TopClient
}

func NewAbility1475(client *topsdk.TopClient) *Ability1475 {
	return &Ability1475{client}
}

/*
   rt回传采购价
*/
func (ability *Ability1475) AlibabaWdkPurchasePrice(req *request2.AlibabaWdkPurchasePriceRequest, session string) (*response2.AlibabaWdkPurchasePriceResponse, error) {
	if ability.Client == nil {
		return nil, errors.New("Ability1475 topClient is nil")
	}
	var jsonStr, err = ability.Client.ExecuteWithSession("alibaba.wdk.purchase.price", req.ToMap(), req.ToFileMap(), session)
	var respStruct = response2.AlibabaWdkPurchasePriceResponse{}
	if err != nil {
		log.Println("alibabaWdkPurchasePrice 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 *Ability1475) AlibabaWdkMerchantRoutingRegister(req *request2.AlibabaWdkMerchantRoutingRegisterRequest, session string) (*response2.AlibabaWdkMerchantRoutingRegisterResponse, error) {
	if ability.Client == nil {
		return nil, errors.New("Ability1475 topClient is nil")
	}
	var jsonStr, err = ability.Client.ExecuteWithSession("alibaba.wdk.merchant.routing.register", req.ToMap(), req.ToFileMap(), session)
	var respStruct = response2.AlibabaWdkMerchantRoutingRegisterResponse{}
	if err != nil {
		log.Println("alibabaWdkMerchantRoutingRegister 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 *Ability1475) AlibabaWdkTimeGet(req *request2.AlibabaWdkTimeGetRequest) (*response2.AlibabaWdkTimeGetResponse, error) {
	if ability.Client == nil {
		return nil, errors.New("Ability1475 topClient is nil")
	}
	var jsonStr, err = ability.Client.Execute("alibaba.wdk.time.get", req.ToMap(), req.ToFileMap())
	var respStruct = response2.AlibabaWdkTimeGetResponse{}
	if err != nil {
		log.Println("alibabaWdkTimeGet 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 *Ability1475) AlibabaWdkPictureUpload(req *request2.AlibabaWdkPictureUploadRequest, session string) (*response2.AlibabaWdkPictureUploadResponse, error) {
	if ability.Client == nil {
		return nil, errors.New("Ability1475 topClient is nil")
	}
	var jsonStr, err = ability.Client.ExecuteWithSession("alibaba.wdk.picture.upload", req.ToMap(), req.ToFileMap(), session)
	var respStruct = response2.AlibabaWdkPictureUploadResponse{}
	if err != nil {
		log.Println("alibabaWdkPictureUpload error", err)
		return &respStruct, err
	}
	err = util.HandleJsonResponse(jsonStr, &respStruct)
	if respStruct.Body == "" || len(respStruct.Body) == 0 {
		respStruct.Body = jsonStr
	}
	return &respStruct, err
}
