package biz_ipdb

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

// DescribeIpSegments invokes the biz_ipdb.DescribeIpSegments API synchronously
func (client *Client) DescribeIpSegments(request *DescribeIpSegmentsRequest) (response *DescribeIpSegmentsResponse, err error) {
	response = CreateDescribeIpSegmentsResponse()
	err = client.DoAction(request, response)
	return
}

// DescribeIpSegmentsWithChan invokes the biz_ipdb.DescribeIpSegments API asynchronously
func (client *Client) DescribeIpSegmentsWithChan(request *DescribeIpSegmentsRequest) (<-chan *DescribeIpSegmentsResponse, <-chan error) {
	responseChan := make(chan *DescribeIpSegmentsResponse, 1)
	errChan := make(chan error, 1)
	err := client.AddAsyncTask(func() {
		defer close(responseChan)
		defer close(errChan)
		response, err := client.DescribeIpSegments(request)
		if err != nil {
			errChan <- err
		} else {
			responseChan <- response
		}
	})
	if err != nil {
		errChan <- err
		close(responseChan)
		close(errChan)
	}
	return responseChan, errChan
}

// DescribeIpSegmentsWithCallback invokes the biz_ipdb.DescribeIpSegments API asynchronously
func (client *Client) DescribeIpSegmentsWithCallback(request *DescribeIpSegmentsRequest, callback func(response *DescribeIpSegmentsResponse, err error)) <-chan int {
	result := make(chan int, 1)
	err := client.AddAsyncTask(func() {
		var response *DescribeIpSegmentsResponse
		var err error
		defer close(result)
		response, err = client.DescribeIpSegments(request)
		callback(response, err)
		result <- 1
	})
	if err != nil {
		defer close(result)
		callback(nil, err)
		result <- 0
	}
	return result
}

// DescribeIpSegmentsRequest is the request struct for api DescribeIpSegments
type DescribeIpSegmentsRequest struct {
	*requests.RpcRequest
	PageSize     string `position:"Query" name:"PageSize"`
	BizLine      string `position:"Query" name:"BizLine"`
	PageNumber   string `position:"Query" name:"PageNumber"`
	NetworkScope string `position:"Query" name:"NetworkScope"`
	RegionNo     string `position:"Query" name:"RegionNo"`
}

// DescribeIpSegmentsResponse is the response struct for api DescribeIpSegments
type DescribeIpSegmentsResponse struct {
	*responses.BaseResponse
	RequestId  string                         `json:"RequestId" xml:"RequestId"`
	PageNumber int                            `json:"PageNumber" xml:"PageNumber"`
	PageSize   int                            `json:"PageSize" xml:"PageSize"`
	TotalCount int                            `json:"TotalCount" xml:"TotalCount"`
	IpSegments IpSegmentsInDescribeIpSegments `json:"IpSegments" xml:"IpSegments"`
}

// CreateDescribeIpSegmentsRequest creates a request to invoke DescribeIpSegments API
func CreateDescribeIpSegmentsRequest() (request *DescribeIpSegmentsRequest) {
	request = &DescribeIpSegmentsRequest{
		RpcRequest: &requests.RpcRequest{},
	}
	request.InitWithApiInfo("Biz-ipdb", "2016-08-08", "DescribeIpSegments", "", "")
	request.Method = requests.POST
	return
}

// CreateDescribeIpSegmentsResponse creates a response to parse from DescribeIpSegments response
func CreateDescribeIpSegmentsResponse() (response *DescribeIpSegmentsResponse) {
	response = &DescribeIpSegmentsResponse{
		BaseResponse: &responses.BaseResponse{},
	}
	return
}
