package ecd

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

// CreateNetworkPackage invokes the ecd.CreateNetworkPackage API synchronously
func (client *Client) CreateNetworkPackage(request *CreateNetworkPackageRequest) (response *CreateNetworkPackageResponse, err error) {
	response = CreateCreateNetworkPackageResponse()
	err = client.DoAction(request, response)
	return
}

// CreateNetworkPackageWithChan invokes the ecd.CreateNetworkPackage API asynchronously
func (client *Client) CreateNetworkPackageWithChan(request *CreateNetworkPackageRequest) (<-chan *CreateNetworkPackageResponse, <-chan error) {
	responseChan := make(chan *CreateNetworkPackageResponse, 1)
	errChan := make(chan error, 1)
	err := client.AddAsyncTask(func() {
		defer close(responseChan)
		defer close(errChan)
		response, err := client.CreateNetworkPackage(request)
		if err != nil {
			errChan <- err
		} else {
			responseChan <- response
		}
	})
	if err != nil {
		errChan <- err
		close(responseChan)
		close(errChan)
	}
	return responseChan, errChan
}

// CreateNetworkPackageWithCallback invokes the ecd.CreateNetworkPackage API asynchronously
func (client *Client) CreateNetworkPackageWithCallback(request *CreateNetworkPackageRequest, callback func(response *CreateNetworkPackageResponse, err error)) <-chan int {
	result := make(chan int, 1)
	err := client.AddAsyncTask(func() {
		var response *CreateNetworkPackageResponse
		var err error
		defer close(result)
		response, err = client.CreateNetworkPackage(request)
		callback(response, err)
		result <- 1
	})
	if err != nil {
		defer close(result)
		callback(nil, err)
		result <- 0
	}
	return result
}

// CreateNetworkPackageRequest is the request struct for api CreateNetworkPackage
type CreateNetworkPackageRequest struct {
	*requests.RpcRequest
	OfficeSiteId       string           `position:"Query" name:"OfficeSiteId"`
	Period             requests.Integer `position:"Query" name:"Period"`
	AutoPay            requests.Boolean `position:"Query" name:"AutoPay"`
	Bandwidth          requests.Integer `position:"Query" name:"Bandwidth"`
	PromotionId        string           `position:"Query" name:"PromotionId"`
	PeriodUnit         string           `position:"Query" name:"PeriodUnit"`
	AutoRenew          requests.Boolean `position:"Query" name:"AutoRenew"`
	InternetChargeType string           `position:"Query" name:"InternetChargeType"`
	PayType            string           `position:"Query" name:"PayType"`
}

// CreateNetworkPackageResponse is the response struct for api CreateNetworkPackage
type CreateNetworkPackageResponse struct {
	*responses.BaseResponse
	NetworkPackageId string `json:"NetworkPackageId" xml:"NetworkPackageId"`
	RequestId        string `json:"RequestId" xml:"RequestId"`
	OrderId          string `json:"OrderId" xml:"OrderId"`
}

// CreateCreateNetworkPackageRequest creates a request to invoke CreateNetworkPackage API
func CreateCreateNetworkPackageRequest() (request *CreateNetworkPackageRequest) {
	request = &CreateNetworkPackageRequest{
		RpcRequest: &requests.RpcRequest{},
	}
	request.InitWithApiInfo("ecd", "2020-09-30", "CreateNetworkPackage", "gwsecd", "openAPI")
	request.Method = requests.POST
	return
}

// CreateCreateNetworkPackageResponse creates a response to parse from CreateNetworkPackage response
func CreateCreateNetworkPackageResponse() (response *CreateNetworkPackageResponse) {
	response = &CreateNetworkPackageResponse{
		BaseResponse: &responses.BaseResponse{},
	}
	return
}
