package actiontrail

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

// LookupEvents invokes the actiontrail.LookupEvents API synchronously
// api document: https://help.aliyun.com/api/actiontrail/lookupevents.html
func (client *Client) LookupEvents(request *LookupEventsRequest) (response *LookupEventsResponse, err error) {
	response = CreateLookupEventsResponse()
	err = client.DoAction(request, response)
	return
}

// LookupEventsWithChan invokes the actiontrail.LookupEvents API asynchronously
// api document: https://help.aliyun.com/api/actiontrail/lookupevents.html
// asynchronous document: https://help.aliyun.com/document_detail/66220.html
func (client *Client) LookupEventsWithChan(request *LookupEventsRequest) (<-chan *LookupEventsResponse, <-chan error) {
	responseChan := make(chan *LookupEventsResponse, 1)
	errChan := make(chan error, 1)
	err := client.AddAsyncTask(func() {
		defer close(responseChan)
		defer close(errChan)
		response, err := client.LookupEvents(request)
		if err != nil {
			errChan <- err
		} else {
			responseChan <- response
		}
	})
	if err != nil {
		errChan <- err
		close(responseChan)
		close(errChan)
	}
	return responseChan, errChan
}

// LookupEventsWithCallback invokes the actiontrail.LookupEvents API asynchronously
// api document: https://help.aliyun.com/api/actiontrail/lookupevents.html
// asynchronous document: https://help.aliyun.com/document_detail/66220.html
func (client *Client) LookupEventsWithCallback(request *LookupEventsRequest, callback func(response *LookupEventsResponse, err error)) <-chan int {
	result := make(chan int, 1)
	err := client.AddAsyncTask(func() {
		var response *LookupEventsResponse
		var err error
		defer close(result)
		response, err = client.LookupEvents(request)
		callback(response, err)
		result <- 1
	})
	if err != nil {
		defer close(result)
		callback(nil, err)
		result <- 0
	}
	return result
}

// LookupEventsRequest is the request struct for api LookupEvents
type LookupEventsRequest struct {
	*requests.RpcRequest
	Request          string `position:"Query" name:"Request"`
	EventAccessKeyId string `position:"Query" name:"EventAccessKeyId"`
	EndTime          string `position:"Query" name:"EndTime"`
	EventRW          string `position:"Query" name:"EventRW"`
	StartTime        string `position:"Query" name:"StartTime"`
	ResourceType     string `position:"Query" name:"ResourceType"`
	EventName        string `position:"Query" name:"EventName"`
	NextToken        string `position:"Query" name:"NextToken"`
	MaxResults       string `position:"Query" name:"MaxResults"`
	EventType        string `position:"Query" name:"EventType"`
	ServiceName      string `position:"Query" name:"ServiceName"`
	ResourceName     string `position:"Query" name:"ResourceName"`
	Event            string `position:"Query" name:"Event"`
	User             string `position:"Query" name:"User"`
}

// LookupEventsResponse is the response struct for api LookupEvents
type LookupEventsResponse struct {
	*responses.BaseResponse
	RequestId string   `json:"RequestId" xml:"RequestId"`
	NextToken string   `json:"NextToken" xml:"NextToken"`
	StartTime string   `json:"StartTime" xml:"StartTime"`
	EndTime   string   `json:"EndTime" xml:"EndTime"`
	Events    []string `json:"Events" xml:"Events"`
}

// CreateLookupEventsRequest creates a request to invoke LookupEvents API
func CreateLookupEventsRequest() (request *LookupEventsRequest) {
	request = &LookupEventsRequest{
		RpcRequest: &requests.RpcRequest{},
	}
	request.InitWithApiInfo("Actiontrail", "2017-12-04", "LookupEvents", "actiontrail", "openAPI")
	return
}

// CreateLookupEventsResponse creates a response to parse from LookupEvents response
func CreateLookupEventsResponse() (response *LookupEventsResponse) {
	response = &LookupEventsResponse{
		BaseResponse: &responses.BaseResponse{},
	}
	return
}
