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"
)

// ListTemplate invokes the bpstudio.ListTemplate API synchronously
func (client *Client) ListTemplate(request *ListTemplateRequest) (response *ListTemplateResponse, err error) {
	response = CreateListTemplateResponse()
	err = client.DoAction(request, response)
	return
}

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

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

// ListTemplateRequest is the request struct for api ListTemplate
type ListTemplateRequest struct {
	*requests.RpcRequest
	Type            string           `position:"Body" name:"Type"`
	TagList         requests.Integer `position:"Body" name:"TagList"`
	ResourceGroupId string           `position:"Body" name:"ResourceGroupId"`
	NextToken       requests.Integer `position:"Body" name:"NextToken"`
	MaxResults      requests.Integer `position:"Body" name:"MaxResults"`
	Keyword         string           `position:"Body" name:"Keyword"`
	OrderType       requests.Integer `position:"Body" name:"OrderType"`
}

// ListTemplateResponse is the response struct for api ListTemplate
type ListTemplateResponse struct {
	*responses.BaseResponse
	TotalCount int    `json:"TotalCount" xml:"TotalCount"`
	Message    string `json:"Message" xml:"Message"`
	NextToken  int    `json:"NextToken" xml:"NextToken"`
	RequestId  string `json:"RequestId" xml:"RequestId"`
	Code       int    `json:"Code" xml:"Code"`
	Data       []Item `json:"Data" xml:"Data"`
}

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

// CreateListTemplateResponse creates a response to parse from ListTemplate response
func CreateListTemplateResponse() (response *ListTemplateResponse) {
	response = &ListTemplateResponse{
		BaseResponse: &responses.BaseResponse{},
	}
	return
}
