/*
Merlin

API Guide for accessing Merlin's model management, deployment, and serving functionalities

API version: 0.14.0
*/

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

package client

import (
	"bytes"
	"context"
	"io"
	"net/http"
	"net/url"
	"strings"
)

// EndpointAPIService EndpointAPI service
type EndpointAPIService service

type ApiModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGetRequest struct {
	ctx        context.Context
	ApiService *EndpointAPIService
	modelId    int32
	versionId  int32
	endpointId string
}

func (r ApiModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGetRequest) Execute() (*Container, *http.Response, error) {
	return r.ApiService.ModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGetExecute(r)
}

/*
ModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGet Get all container belong to a version endpoint

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param modelId
	@param versionId
	@param endpointId
	@return ApiModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGetRequest
*/
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGet(ctx context.Context, modelId int32, versionId int32, endpointId string) ApiModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGetRequest {
	return ApiModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGetRequest{
		ApiService: a,
		ctx:        ctx,
		modelId:    modelId,
		versionId:  versionId,
		endpointId: endpointId,
	}
}

// Execute executes the request
//
//	@return Container
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGetExecute(r ApiModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGetRequest) (*Container, *http.Response, error) {
	var (
		localVarHTTPMethod  = http.MethodGet
		localVarPostBody    interface{}
		formFiles           []formFile
		localVarReturnValue *Container
	)

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

	localVarPath := localBasePath + "/models/{model_id}/versions/{version_id}/endpoint/{endpoint_id}/containers"
	localVarPath = strings.Replace(localVarPath, "{"+"model_id"+"}", url.PathEscape(parameterValueToString(r.modelId, "modelId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"version_id"+"}", url.PathEscape(parameterValueToString(r.versionId, "versionId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"endpoint_id"+"}", url.PathEscape(parameterValueToString(r.endpointId, "endpointId")), -1)

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := url.Values{}
	localVarFormParams := url.Values{}

	// 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{"*/*"}

	// set Accept header
	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
	if localVarHTTPHeaderAccept != "" {
		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
	}
	if r.ctx != nil {
		// API Key Authentication
		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
			if apiKey, ok := auth["Bearer"]; ok {
				var key string
				if apiKey.Prefix != "" {
					key = apiKey.Prefix + " " + apiKey.Key
				} else {
					key = apiKey.Key
				}
				localVarHeaderParams["Authorization"] = key
			}
		}
	}
	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 := io.ReadAll(localVarHTTPResponse.Body)
	localVarHTTPResponse.Body.Close()
	localVarHTTPResponse.Body = io.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 ApiModelsModelIdVersionsVersionIdEndpointEndpointIdDeleteRequest struct {
	ctx        context.Context
	ApiService *EndpointAPIService
	modelId    int32
	versionId  int32
	endpointId string
}

func (r ApiModelsModelIdVersionsVersionIdEndpointEndpointIdDeleteRequest) Execute() (*http.Response, error) {
	return r.ApiService.ModelsModelIdVersionsVersionIdEndpointEndpointIdDeleteExecute(r)
}

/*
ModelsModelIdVersionsVersionIdEndpointEndpointIdDelete Undeploy the specified model version deployment

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param modelId
	@param versionId
	@param endpointId
	@return ApiModelsModelIdVersionsVersionIdEndpointEndpointIdDeleteRequest
*/
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointEndpointIdDelete(ctx context.Context, modelId int32, versionId int32, endpointId string) ApiModelsModelIdVersionsVersionIdEndpointEndpointIdDeleteRequest {
	return ApiModelsModelIdVersionsVersionIdEndpointEndpointIdDeleteRequest{
		ApiService: a,
		ctx:        ctx,
		modelId:    modelId,
		versionId:  versionId,
		endpointId: endpointId,
	}
}

// Execute executes the request
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointEndpointIdDeleteExecute(r ApiModelsModelIdVersionsVersionIdEndpointEndpointIdDeleteRequest) (*http.Response, error) {
	var (
		localVarHTTPMethod = http.MethodDelete
		localVarPostBody   interface{}
		formFiles          []formFile
	)

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

	localVarPath := localBasePath + "/models/{model_id}/versions/{version_id}/endpoint/{endpoint_id}"
	localVarPath = strings.Replace(localVarPath, "{"+"model_id"+"}", url.PathEscape(parameterValueToString(r.modelId, "modelId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"version_id"+"}", url.PathEscape(parameterValueToString(r.versionId, "versionId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"endpoint_id"+"}", url.PathEscape(parameterValueToString(r.endpointId, "endpointId")), -1)

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := url.Values{}
	localVarFormParams := url.Values{}

	// 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{}

	// set Accept header
	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
	if localVarHTTPHeaderAccept != "" {
		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
	}
	if r.ctx != nil {
		// API Key Authentication
		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
			if apiKey, ok := auth["Bearer"]; ok {
				var key string
				if apiKey.Prefix != "" {
					key = apiKey.Prefix + " " + apiKey.Key
				} else {
					key = apiKey.Key
				}
				localVarHeaderParams["Authorization"] = key
			}
		}
	}
	req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
	if err != nil {
		return nil, err
	}

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

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

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

	return localVarHTTPResponse, nil
}

type ApiModelsModelIdVersionsVersionIdEndpointEndpointIdGetRequest struct {
	ctx        context.Context
	ApiService *EndpointAPIService
	modelId    int32
	versionId  int32
	endpointId string
}

func (r ApiModelsModelIdVersionsVersionIdEndpointEndpointIdGetRequest) Execute() (*VersionEndpoint, *http.Response, error) {
	return r.ApiService.ModelsModelIdVersionsVersionIdEndpointEndpointIdGetExecute(r)
}

/*
ModelsModelIdVersionsVersionIdEndpointEndpointIdGet Get version endpoint resource

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param modelId
	@param versionId
	@param endpointId
	@return ApiModelsModelIdVersionsVersionIdEndpointEndpointIdGetRequest
*/
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointEndpointIdGet(ctx context.Context, modelId int32, versionId int32, endpointId string) ApiModelsModelIdVersionsVersionIdEndpointEndpointIdGetRequest {
	return ApiModelsModelIdVersionsVersionIdEndpointEndpointIdGetRequest{
		ApiService: a,
		ctx:        ctx,
		modelId:    modelId,
		versionId:  versionId,
		endpointId: endpointId,
	}
}

// Execute executes the request
//
//	@return VersionEndpoint
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointEndpointIdGetExecute(r ApiModelsModelIdVersionsVersionIdEndpointEndpointIdGetRequest) (*VersionEndpoint, *http.Response, error) {
	var (
		localVarHTTPMethod  = http.MethodGet
		localVarPostBody    interface{}
		formFiles           []formFile
		localVarReturnValue *VersionEndpoint
	)

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

	localVarPath := localBasePath + "/models/{model_id}/versions/{version_id}/endpoint/{endpoint_id}"
	localVarPath = strings.Replace(localVarPath, "{"+"model_id"+"}", url.PathEscape(parameterValueToString(r.modelId, "modelId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"version_id"+"}", url.PathEscape(parameterValueToString(r.versionId, "versionId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"endpoint_id"+"}", url.PathEscape(parameterValueToString(r.endpointId, "endpointId")), -1)

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := url.Values{}
	localVarFormParams := url.Values{}

	// 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{"*/*"}

	// set Accept header
	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
	if localVarHTTPHeaderAccept != "" {
		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
	}
	if r.ctx != nil {
		// API Key Authentication
		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
			if apiKey, ok := auth["Bearer"]; ok {
				var key string
				if apiKey.Prefix != "" {
					key = apiKey.Prefix + " " + apiKey.Key
				} else {
					key = apiKey.Key
				}
				localVarHeaderParams["Authorization"] = key
			}
		}
	}
	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 := io.ReadAll(localVarHTTPResponse.Body)
	localVarHTTPResponse.Body.Close()
	localVarHTTPResponse.Body = io.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 ApiModelsModelIdVersionsVersionIdEndpointEndpointIdPutRequest struct {
	ctx        context.Context
	ApiService *EndpointAPIService
	modelId    int32
	versionId  int32
	endpointId string
	body       *VersionEndpoint
}

func (r ApiModelsModelIdVersionsVersionIdEndpointEndpointIdPutRequest) Body(body VersionEndpoint) ApiModelsModelIdVersionsVersionIdEndpointEndpointIdPutRequest {
	r.body = &body
	return r
}

func (r ApiModelsModelIdVersionsVersionIdEndpointEndpointIdPutRequest) Execute() (*VersionEndpoint, *http.Response, error) {
	return r.ApiService.ModelsModelIdVersionsVersionIdEndpointEndpointIdPutExecute(r)
}

/*
ModelsModelIdVersionsVersionIdEndpointEndpointIdPut Modify version endpoint, this API will redeploy the associated deployment

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param modelId
	@param versionId
	@param endpointId
	@return ApiModelsModelIdVersionsVersionIdEndpointEndpointIdPutRequest
*/
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointEndpointIdPut(ctx context.Context, modelId int32, versionId int32, endpointId string) ApiModelsModelIdVersionsVersionIdEndpointEndpointIdPutRequest {
	return ApiModelsModelIdVersionsVersionIdEndpointEndpointIdPutRequest{
		ApiService: a,
		ctx:        ctx,
		modelId:    modelId,
		versionId:  versionId,
		endpointId: endpointId,
	}
}

// Execute executes the request
//
//	@return VersionEndpoint
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointEndpointIdPutExecute(r ApiModelsModelIdVersionsVersionIdEndpointEndpointIdPutRequest) (*VersionEndpoint, *http.Response, error) {
	var (
		localVarHTTPMethod  = http.MethodPut
		localVarPostBody    interface{}
		formFiles           []formFile
		localVarReturnValue *VersionEndpoint
	)

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

	localVarPath := localBasePath + "/models/{model_id}/versions/{version_id}/endpoint/{endpoint_id}"
	localVarPath = strings.Replace(localVarPath, "{"+"model_id"+"}", url.PathEscape(parameterValueToString(r.modelId, "modelId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"version_id"+"}", url.PathEscape(parameterValueToString(r.versionId, "versionId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"endpoint_id"+"}", url.PathEscape(parameterValueToString(r.endpointId, "endpointId")), -1)

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := url.Values{}
	localVarFormParams := url.Values{}

	// 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{"*/*"}

	// set Accept header
	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
	if localVarHTTPHeaderAccept != "" {
		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
	}
	// body params
	localVarPostBody = r.body
	if r.ctx != nil {
		// API Key Authentication
		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
			if apiKey, ok := auth["Bearer"]; ok {
				var key string
				if apiKey.Prefix != "" {
					key = apiKey.Prefix + " " + apiKey.Key
				} else {
					key = apiKey.Key
				}
				localVarHeaderParams["Authorization"] = key
			}
		}
	}
	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 := io.ReadAll(localVarHTTPResponse.Body)
	localVarHTTPResponse.Body.Close()
	localVarHTTPResponse.Body = io.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 ApiModelsModelIdVersionsVersionIdEndpointGetRequest struct {
	ctx        context.Context
	ApiService *EndpointAPIService
	modelId    int32
	versionId  int32
}

func (r ApiModelsModelIdVersionsVersionIdEndpointGetRequest) Execute() ([]VersionEndpoint, *http.Response, error) {
	return r.ApiService.ModelsModelIdVersionsVersionIdEndpointGetExecute(r)
}

/*
ModelsModelIdVersionsVersionIdEndpointGet List all endpoint of a model version

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param modelId
	@param versionId
	@return ApiModelsModelIdVersionsVersionIdEndpointGetRequest
*/
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointGet(ctx context.Context, modelId int32, versionId int32) ApiModelsModelIdVersionsVersionIdEndpointGetRequest {
	return ApiModelsModelIdVersionsVersionIdEndpointGetRequest{
		ApiService: a,
		ctx:        ctx,
		modelId:    modelId,
		versionId:  versionId,
	}
}

// Execute executes the request
//
//	@return []VersionEndpoint
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointGetExecute(r ApiModelsModelIdVersionsVersionIdEndpointGetRequest) ([]VersionEndpoint, *http.Response, error) {
	var (
		localVarHTTPMethod  = http.MethodGet
		localVarPostBody    interface{}
		formFiles           []formFile
		localVarReturnValue []VersionEndpoint
	)

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

	localVarPath := localBasePath + "/models/{model_id}/versions/{version_id}/endpoint"
	localVarPath = strings.Replace(localVarPath, "{"+"model_id"+"}", url.PathEscape(parameterValueToString(r.modelId, "modelId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"version_id"+"}", url.PathEscape(parameterValueToString(r.versionId, "versionId")), -1)

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := url.Values{}
	localVarFormParams := url.Values{}

	// 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{"*/*"}

	// set Accept header
	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
	if localVarHTTPHeaderAccept != "" {
		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
	}
	if r.ctx != nil {
		// API Key Authentication
		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
			if apiKey, ok := auth["Bearer"]; ok {
				var key string
				if apiKey.Prefix != "" {
					key = apiKey.Prefix + " " + apiKey.Key
				} else {
					key = apiKey.Key
				}
				localVarHeaderParams["Authorization"] = key
			}
		}
	}
	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 := io.ReadAll(localVarHTTPResponse.Body)
	localVarHTTPResponse.Body.Close()
	localVarHTTPResponse.Body = io.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 ApiModelsModelIdVersionsVersionIdEndpointPostRequest struct {
	ctx        context.Context
	ApiService *EndpointAPIService
	modelId    int32
	versionId  int32
	body       *VersionEndpoint
}

func (r ApiModelsModelIdVersionsVersionIdEndpointPostRequest) Body(body VersionEndpoint) ApiModelsModelIdVersionsVersionIdEndpointPostRequest {
	r.body = &body
	return r
}

func (r ApiModelsModelIdVersionsVersionIdEndpointPostRequest) Execute() (*VersionEndpoint, *http.Response, error) {
	return r.ApiService.ModelsModelIdVersionsVersionIdEndpointPostExecute(r)
}

/*
ModelsModelIdVersionsVersionIdEndpointPost Deploy specific version of the models

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param modelId
	@param versionId
	@return ApiModelsModelIdVersionsVersionIdEndpointPostRequest
*/
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointPost(ctx context.Context, modelId int32, versionId int32) ApiModelsModelIdVersionsVersionIdEndpointPostRequest {
	return ApiModelsModelIdVersionsVersionIdEndpointPostRequest{
		ApiService: a,
		ctx:        ctx,
		modelId:    modelId,
		versionId:  versionId,
	}
}

// Execute executes the request
//
//	@return VersionEndpoint
func (a *EndpointAPIService) ModelsModelIdVersionsVersionIdEndpointPostExecute(r ApiModelsModelIdVersionsVersionIdEndpointPostRequest) (*VersionEndpoint, *http.Response, error) {
	var (
		localVarHTTPMethod  = http.MethodPost
		localVarPostBody    interface{}
		formFiles           []formFile
		localVarReturnValue *VersionEndpoint
	)

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

	localVarPath := localBasePath + "/models/{model_id}/versions/{version_id}/endpoint"
	localVarPath = strings.Replace(localVarPath, "{"+"model_id"+"}", url.PathEscape(parameterValueToString(r.modelId, "modelId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"version_id"+"}", url.PathEscape(parameterValueToString(r.versionId, "versionId")), -1)

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := url.Values{}
	localVarFormParams := url.Values{}

	// 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{"*/*"}

	// set Accept header
	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
	if localVarHTTPHeaderAccept != "" {
		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
	}
	// body params
	localVarPostBody = r.body
	if r.ctx != nil {
		// API Key Authentication
		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
			if apiKey, ok := auth["Bearer"]; ok {
				var key string
				if apiKey.Prefix != "" {
					key = apiKey.Prefix + " " + apiKey.Key
				} else {
					key = apiKey.Key
				}
				localVarHeaderParams["Authorization"] = key
			}
		}
	}
	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 := io.ReadAll(localVarHTTPResponse.Body)
	localVarHTTPResponse.Body.Close()
	localVarHTTPResponse.Body = io.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
}
