package workorder

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

// ListTickets invokes the workorder.ListTickets API synchronously
func (client *Client) ListTickets(request *ListTicketsRequest) (response *ListTicketsResponse, err error) {
	response = CreateListTicketsResponse()
	err = client.DoAction(request, response)
	return
}

// ListTicketsWithChan invokes the workorder.ListTickets API asynchronously
func (client *Client) ListTicketsWithChan(request *ListTicketsRequest) (<-chan *ListTicketsResponse, <-chan error) {
	responseChan := make(chan *ListTicketsResponse, 1)
	errChan := make(chan error, 1)
	err := client.AddAsyncTask(func() {
		defer close(responseChan)
		defer close(errChan)
		response, err := client.ListTickets(request)
		if err != nil {
			errChan <- err
		} else {
			responseChan <- response
		}
	})
	if err != nil {
		errChan <- err
		close(responseChan)
		close(errChan)
	}
	return responseChan, errChan
}

// ListTicketsWithCallback invokes the workorder.ListTickets API asynchronously
func (client *Client) ListTicketsWithCallback(request *ListTicketsRequest, callback func(response *ListTicketsResponse, err error)) <-chan int {
	result := make(chan int, 1)
	err := client.AddAsyncTask(func() {
		var response *ListTicketsResponse
		var err error
		defer close(result)
		response, err = client.ListTickets(request)
		callback(response, err)
		result <- 1
	})
	if err != nil {
		defer close(result)
		callback(nil, err)
		result <- 0
	}
	return result
}

// ListTicketsRequest is the request struct for api ListTickets
type ListTicketsRequest struct {
	*requests.RpcRequest
	StatusList *[]string        `position:"Body" name:"StatusList"  type:"Repeated"`
	StartDate  requests.Integer `position:"Body" name:"StartDate"`
	PageNumber requests.Integer `position:"Query" name:"PageNumber"`
	EndDate    requests.Integer `position:"Body" name:"EndDate"`
	PageSize   requests.Integer `position:"Query" name:"PageSize"`
	Keyword    string           `position:"Body" name:"Keyword"`
	TicketId   string           `position:"Body" name:"TicketId"`
}

// ListTicketsResponse is the response struct for api ListTickets
type ListTicketsResponse struct {
	*responses.BaseResponse
	Code       int                     `json:"Code" xml:"Code"`
	RequestId  string                  `json:"RequestId" xml:"RequestId"`
	Message    string                  `json:"Message" xml:"Message"`
	PageNumber int                     `json:"PageNumber" xml:"PageNumber"`
	PageSize   int                     `json:"PageSize" xml:"PageSize"`
	TotalCount int64                   `json:"TotalCount" xml:"TotalCount"`
	Success    bool                    `json:"Success" xml:"Success"`
	Data       []DataItemInListTickets `json:"Data" xml:"Data"`
}

// CreateListTicketsRequest creates a request to invoke ListTickets API
func CreateListTicketsRequest() (request *ListTicketsRequest) {
	request = &ListTicketsRequest{
		RpcRequest: &requests.RpcRequest{},
	}
	request.InitWithApiInfo("Workorder", "2021-06-10", "ListTickets", "", "")
	request.Method = requests.POST
	return
}

// CreateListTicketsResponse creates a response to parse from ListTickets response
func CreateListTicketsResponse() (response *ListTicketsResponse) {
	response = &ListTicketsResponse{
		BaseResponse: &responses.BaseResponse{},
	}
	return
}
