package bpstudio

//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//
// Code generated by Alibaba Cloud SDK Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

import (
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
)

// ValuateTemplate invokes the bpstudio.ValuateTemplate API synchronously
func (client *Client) ValuateTemplate(request *ValuateTemplateRequest) (response *ValuateTemplateResponse, err error) {
	response = CreateValuateTemplateResponse()
	err = client.DoAction(request, response)
	return
}

// ValuateTemplateWithChan invokes the bpstudio.ValuateTemplate API asynchronously
func (client *Client) ValuateTemplateWithChan(request *ValuateTemplateRequest) (<-chan *ValuateTemplateResponse, <-chan error) {
	responseChan := make(chan *ValuateTemplateResponse, 1)
	errChan := make(chan error, 1)
	err := client.AddAsyncTask(func() {
		defer close(responseChan)
		defer close(errChan)
		response, err := client.ValuateTemplate(request)
		if err != nil {
			errChan <- err
		} else {
			responseChan <- response
		}
	})
	if err != nil {
		errChan <- err
		close(responseChan)
		close(errChan)
	}
	return responseChan, errChan
}

// ValuateTemplateWithCallback invokes the bpstudio.ValuateTemplate API asynchronously
func (client *Client) ValuateTemplateWithCallback(request *ValuateTemplateRequest, callback func(response *ValuateTemplateResponse, err error)) <-chan int {
	result := make(chan int, 1)
	err := client.AddAsyncTask(func() {
		var response *ValuateTemplateResponse
		var err error
		defer close(result)
		response, err = client.ValuateTemplate(request)
		callback(response, err)
		result <- 1
	})
	if err != nil {
		defer close(result)
		callback(nil, err)
		result <- 0
	}
	return result
}

// ValuateTemplateRequest is the request struct for api ValuateTemplate
type ValuateTemplateRequest struct {
	*requests.RpcRequest
	Variables       map[string]string           `position:"Body" name:"Variables"  type:"Map"`
	ClientToken     string                      `position:"Body" name:"ClientToken"`
	Instances       *[]ValuateTemplateInstances `position:"Body" name:"Instances"  type:"Json"`
	TemplateId      string                      `position:"Body" name:"TemplateId"`
	ResourceGroupId string                      `position:"Body" name:"ResourceGroupId"`
	AreaId          string                      `position:"Body" name:"AreaId"`
}

// ValuateTemplateInstances is a repeated param struct in ValuateTemplateRequest
type ValuateTemplateInstances struct {
	NodeName string `name:"NodeName"`
	NodeType string `name:"NodeType"`
	Id       string `name:"Id"`
}

// ValuateTemplateResponse is the response struct for api ValuateTemplate
type ValuateTemplateResponse struct {
	*responses.BaseResponse
	Message   string                `json:"Message" xml:"Message"`
	RequestId string                `json:"RequestId" xml:"RequestId"`
	Code      string                `json:"Code" xml:"Code"`
	Data      DataInValuateTemplate `json:"Data" xml:"Data"`
}

// CreateValuateTemplateRequest creates a request to invoke ValuateTemplate API
func CreateValuateTemplateRequest() (request *ValuateTemplateRequest) {
	request = &ValuateTemplateRequest{
		RpcRequest: &requests.RpcRequest{},
	}
	request.InitWithApiInfo("BPStudio", "2021-09-31", "ValuateTemplate", "bpstudio", "openAPI")
	request.Method = requests.POST
	return
}

// CreateValuateTemplateResponse creates a response to parse from ValuateTemplate response
func CreateValuateTemplateResponse() (response *ValuateTemplateResponse) {
	response = &ValuateTemplateResponse{
		BaseResponse: &responses.BaseResponse{},
	}
	return
}
