package ability202

import (
	"errors"
	"topsdk"
	"topsdk/ability202/request"
	"topsdk/ability202/response"
	"topsdk/util"
)

type Ability202 struct {
	Client *topsdk.TopClient
}

func NewAbility202(client *topsdk.TopClient) *Ability202 {
	return &Ability202{client}
}

/*
分销商提交受理订单
*/
func (ability *Ability202) AlibabaTianjiDistributorOrderSubmit(req *request.AlibabaTianjiDistributorOrderSubmitRequest, session string) (*response.AlibabaTianjiDistributorOrderSubmitResponse, error) {
	if ability.Client == nil {
		return nil, errors.New("Ability202 topClient is nil")
	}
	var jsonStr, err = ability.Client.ExecuteWithSession("alibaba.tianji.distributor.order.submit", req.ToMap(), req.ToFileMap(), session)
	var respStruct = response.AlibabaTianjiDistributorOrderSubmitResponse{}
	if err != nil {
		// log.Println("alibabaTianjiDistributorOrderSubmit error", err)
		return &respStruct, err
	}
	err = util.HandleJsonResponse(jsonStr, &respStruct)
	if respStruct.Body == "" || len(respStruct.Body) == 0 {
		respStruct.Body = jsonStr
	}
	return &respStruct, err
}
