/*
xpan

xpanapi

API version: 0.1
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package openapi

import (
	"bytes"
	_context "context"
	_ioutil "io/ioutil"
	_nethttp "net/http"
	_neturl "net/url"
)

// Linger please
var (
	_ _context.Context
)

// UserinfoApiService UserinfoApi service
type UserinfoApiService service

type ApiApiquotaRequest struct {
	ctx _context.Context
	ApiService *UserinfoApiService
	accessToken *string
	checkexpire *int32
	checkfree *int32
}

func (r ApiApiquotaRequest) AccessToken(accessToken string) ApiApiquotaRequest {
	r.accessToken = &accessToken
	return r
}
func (r ApiApiquotaRequest) Checkexpire(checkexpire int32) ApiApiquotaRequest {
	r.checkexpire = &checkexpire
	return r
}
func (r ApiApiquotaRequest) Checkfree(checkfree int32) ApiApiquotaRequest {
	r.checkfree = &checkfree
	return r
}

func (r ApiApiquotaRequest) Execute() (Quotaresponse, *_nethttp.Response, error) {
	return r.ApiService.ApiquotaExecute(r)
}

/*
Apiquota Method for Apiquota

api quota

 @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @return ApiApiquotaRequest
*/
func (a *UserinfoApiService) Apiquota(ctx _context.Context) ApiApiquotaRequest {
	return ApiApiquotaRequest{
		ApiService: a,
		ctx: ctx,
	}
}

// Execute executes the request
//  @return Quotaresponse
func (a *UserinfoApiService) ApiquotaExecute(r ApiApiquotaRequest) (Quotaresponse, *_nethttp.Response, error) {
	var (
		localVarHTTPMethod   = _nethttp.MethodGet
		localVarPostBody     interface{}
		formFiles            []formFile
		localVarReturnValue  Quotaresponse
	)

	localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "UserinfoApiService.Apiquota")
	if err != nil {
		return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()}
	}

	localVarPath := localBasePath + "/api/quota?openapi=xpansdk"

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := _neturl.Values{}
	localVarFormParams := _neturl.Values{}
	if r.accessToken == nil {
		return localVarReturnValue, nil, reportError("accessToken is required and must be specified")
	}

	localVarQueryParams.Add("access_token", parameterToString(*r.accessToken, ""))
	if r.checkexpire != nil {
		localVarQueryParams.Add("checkexpire", parameterToString(*r.checkexpire, ""))
	}
	if r.checkfree != nil {
		localVarQueryParams.Add("checkfree", parameterToString(*r.checkfree, ""))
	}
	// to determine the Content-Type header
	localVarHTTPContentTypes := []string{}

	// set Content-Type header
	localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
	if localVarHTTPContentType != "" {
		localVarHeaderParams["Content-Type"] = localVarHTTPContentType
	}

	// to determine the Accept header
	localVarHTTPHeaderAccepts := []string{"application/json; charset=UTF-8"}

	// set Accept header
	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
	if localVarHTTPHeaderAccept != "" {
		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
	}
	req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.callAPI(req)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}

	localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body)
	localVarHTTPResponse.Body.Close()
	localVarHTTPResponse.Body = _ioutil.NopCloser(bytes.NewBuffer(localVarBody))
	if err != nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}

	if localVarHTTPResponse.StatusCode >= 300 {
		newErr := GenericOpenAPIError{
			body:  localVarBody,
			error: localVarHTTPResponse.Status,
		}
		return localVarReturnValue, localVarHTTPResponse, newErr
	}

	err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
	if err != nil {
		newErr := GenericOpenAPIError{
			body:  localVarBody,
			error: err.Error(),
		}
		return localVarReturnValue, localVarHTTPResponse, newErr
	}

	return localVarReturnValue, localVarHTTPResponse, nil
}

type ApiXpannasuinfoRequest struct {
	ctx _context.Context
	ApiService *UserinfoApiService
	accessToken *string
}

func (r ApiXpannasuinfoRequest) AccessToken(accessToken string) ApiXpannasuinfoRequest {
	r.accessToken = &accessToken
	return r
}

func (r ApiXpannasuinfoRequest) Execute() (Uinforesponse, *_nethttp.Response, error) {
	return r.ApiService.XpannasuinfoExecute(r)
}

/*
Xpannasuinfo Method for Xpannasuinfo

user info

 @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @return ApiXpannasuinfoRequest
*/
func (a *UserinfoApiService) Xpannasuinfo(ctx _context.Context) ApiXpannasuinfoRequest {
	return ApiXpannasuinfoRequest{
		ApiService: a,
		ctx: ctx,
	}
}

// Execute executes the request
//  @return Uinforesponse
func (a *UserinfoApiService) XpannasuinfoExecute(r ApiXpannasuinfoRequest) (Uinforesponse, *_nethttp.Response, error) {
	var (
		localVarHTTPMethod   = _nethttp.MethodGet
		localVarPostBody     interface{}
		formFiles            []formFile
		localVarReturnValue  Uinforesponse
	)

	localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "UserinfoApiService.Xpannasuinfo")
	if err != nil {
		return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()}
	}

	localVarPath := localBasePath + "/rest/2.0/xpan/nas?method=uinfo&openapi=xpansdk"

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := _neturl.Values{}
	localVarFormParams := _neturl.Values{}
	if r.accessToken == nil {
		return localVarReturnValue, nil, reportError("accessToken is required and must be specified")
	}

	localVarQueryParams.Add("access_token", parameterToString(*r.accessToken, ""))
	// to determine the Content-Type header
	localVarHTTPContentTypes := []string{}

	// set Content-Type header
	localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
	if localVarHTTPContentType != "" {
		localVarHeaderParams["Content-Type"] = localVarHTTPContentType
	}

	// to determine the Accept header
	localVarHTTPHeaderAccepts := []string{"application/json; charset=UTF-8"}

	// set Accept header
	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
	if localVarHTTPHeaderAccept != "" {
		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
	}
	req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.callAPI(req)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}

	localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body)
	localVarHTTPResponse.Body.Close()
	localVarHTTPResponse.Body = _ioutil.NopCloser(bytes.NewBuffer(localVarBody))
	if err != nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}

	if localVarHTTPResponse.StatusCode >= 300 {
		newErr := GenericOpenAPIError{
			body:  localVarBody,
			error: localVarHTTPResponse.Status,
		}
		return localVarReturnValue, localVarHTTPResponse, newErr
	}

	err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
	if err != nil {
		newErr := GenericOpenAPIError{
			body:  localVarBody,
			error: err.Error(),
		}
		return localVarReturnValue, localVarHTTPResponse, newErr
	}

	return localVarReturnValue, localVarHTTPResponse, nil
}
