package idrsservice

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

// ListDepartments invokes the idrsservice.ListDepartments API synchronously
func (client *Client) ListDepartments(request *ListDepartmentsRequest) (response *ListDepartmentsResponse, err error) {
	response = CreateListDepartmentsResponse()
	err = client.DoAction(request, response)
	return
}

// ListDepartmentsWithChan invokes the idrsservice.ListDepartments API asynchronously
func (client *Client) ListDepartmentsWithChan(request *ListDepartmentsRequest) (<-chan *ListDepartmentsResponse, <-chan error) {
	responseChan := make(chan *ListDepartmentsResponse, 1)
	errChan := make(chan error, 1)
	err := client.AddAsyncTask(func() {
		defer close(responseChan)
		defer close(errChan)
		response, err := client.ListDepartments(request)
		if err != nil {
			errChan <- err
		} else {
			responseChan <- response
		}
	})
	if err != nil {
		errChan <- err
		close(responseChan)
		close(errChan)
	}
	return responseChan, errChan
}

// ListDepartmentsWithCallback invokes the idrsservice.ListDepartments API asynchronously
func (client *Client) ListDepartmentsWithCallback(request *ListDepartmentsRequest, callback func(response *ListDepartmentsResponse, err error)) <-chan int {
	result := make(chan int, 1)
	err := client.AddAsyncTask(func() {
		var response *ListDepartmentsResponse
		var err error
		defer close(result)
		response, err = client.ListDepartments(request)
		callback(response, err)
		result <- 1
	})
	if err != nil {
		defer close(result)
		callback(nil, err)
		result <- 0
	}
	return result
}

// ListDepartmentsRequest is the request struct for api ListDepartments
type ListDepartmentsRequest struct {
	*requests.RpcRequest
	UserId    string           `position:"Query" name:"UserId"`
	Name      string           `position:"Query" name:"Name"`
	PageSize  requests.Integer `position:"Query" name:"PageSize"`
	PageIndex requests.Integer `position:"Query" name:"PageIndex"`
}

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

// CreateListDepartmentsRequest creates a request to invoke ListDepartments API
func CreateListDepartmentsRequest() (request *ListDepartmentsRequest) {
	request = &ListDepartmentsRequest{
		RpcRequest: &requests.RpcRequest{},
	}
	request.InitWithApiInfo("idrsservice", "2020-06-30", "ListDepartments", "idrsservice", "openAPI")
	request.Method = requests.POST
	return
}

// CreateListDepartmentsResponse creates a response to parse from ListDepartments response
func CreateListDepartmentsResponse() (response *ListDepartmentsResponse) {
	response = &ListDepartmentsResponse{
		BaseResponse: &responses.BaseResponse{},
	}
	return
}
