/*
Daytona Toolbox API

Daytona Toolbox API

API version: v0.0.0-dev
*/

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

package toolbox

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


type InterpreterAPI interface {

	/*
	CreateInterpreterContext Create a new interpreter context

	Creates a new isolated interpreter context with optional working directory and language

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@return InterpreterAPICreateInterpreterContextRequest
	*/
	CreateInterpreterContext(ctx context.Context) InterpreterAPICreateInterpreterContextRequest

	// CreateInterpreterContextExecute executes the request
	//  @return InterpreterContext
	CreateInterpreterContextExecute(r InterpreterAPICreateInterpreterContextRequest) (*InterpreterContext, *http.Response, error)

	/*
	DeleteInterpreterContext Delete an interpreter context

	Deletes an interpreter context and shuts down its worker process

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param id Context ID
	@return InterpreterAPIDeleteInterpreterContextRequest
	*/
	DeleteInterpreterContext(ctx context.Context, id string) InterpreterAPIDeleteInterpreterContextRequest

	// DeleteInterpreterContextExecute executes the request
	//  @return map[string]string
	DeleteInterpreterContextExecute(r InterpreterAPIDeleteInterpreterContextRequest) (map[string]string, *http.Response, error)

	/*
	ExecuteInterpreterCode Execute code in an interpreter context

	Executes code in a specified context (or default context if not specified) via WebSocket streaming

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@return InterpreterAPIExecuteInterpreterCodeRequest
	*/
	ExecuteInterpreterCode(ctx context.Context) InterpreterAPIExecuteInterpreterCodeRequest

	// ExecuteInterpreterCodeExecute executes the request
	ExecuteInterpreterCodeExecute(r InterpreterAPIExecuteInterpreterCodeRequest) (*http.Response, error)

	/*
	ListInterpreterContexts List all user-created interpreter contexts

	Returns information about all user-created interpreter contexts (excludes default context)

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@return InterpreterAPIListInterpreterContextsRequest
	*/
	ListInterpreterContexts(ctx context.Context) InterpreterAPIListInterpreterContextsRequest

	// ListInterpreterContextsExecute executes the request
	//  @return ListContextsResponse
	ListInterpreterContextsExecute(r InterpreterAPIListInterpreterContextsRequest) (*ListContextsResponse, *http.Response, error)
}

// InterpreterAPIService InterpreterAPI service
type InterpreterAPIService service

type InterpreterAPICreateInterpreterContextRequest struct {
	ctx context.Context
	ApiService InterpreterAPI
	request *CreateContextRequest
}

// Context configuration
func (r InterpreterAPICreateInterpreterContextRequest) Request(request CreateContextRequest) InterpreterAPICreateInterpreterContextRequest {
	r.request = &request
	return r
}

func (r InterpreterAPICreateInterpreterContextRequest) Execute() (*InterpreterContext, *http.Response, error) {
	return r.ApiService.CreateInterpreterContextExecute(r)
}

/*
CreateInterpreterContext Create a new interpreter context

Creates a new isolated interpreter context with optional working directory and language

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

// Execute executes the request
//  @return InterpreterContext
func (a *InterpreterAPIService) CreateInterpreterContextExecute(r InterpreterAPICreateInterpreterContextRequest) (*InterpreterContext, *http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodPost
		localVarPostBody     interface{}
		formFiles            []formFile
		localVarReturnValue  *InterpreterContext
	)

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

	localVarPath := localBasePath + "/process/interpreter/context"

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

	// to determine the Content-Type header
	localVarHTTPContentTypes := []string{"application/json"}

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

	// to determine the Accept header
	localVarHTTPHeaderAccepts := []string{"application/json"}

	// set Accept header
	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
	if localVarHTTPHeaderAccept != "" {
		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
	}
	// body params
	localVarPostBody = r.request
	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,
		}
		if localVarHTTPResponse.StatusCode == 400 {
			var v map[string]string
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarReturnValue, localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarReturnValue, localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 500 {
			var v map[string]string
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarReturnValue, localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
		}
		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 InterpreterAPIDeleteInterpreterContextRequest struct {
	ctx context.Context
	ApiService InterpreterAPI
	id string
}

func (r InterpreterAPIDeleteInterpreterContextRequest) Execute() (map[string]string, *http.Response, error) {
	return r.ApiService.DeleteInterpreterContextExecute(r)
}

/*
DeleteInterpreterContext Delete an interpreter context

Deletes an interpreter context and shuts down its worker process

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param id Context ID
 @return InterpreterAPIDeleteInterpreterContextRequest
*/
func (a *InterpreterAPIService) DeleteInterpreterContext(ctx context.Context, id string) InterpreterAPIDeleteInterpreterContextRequest {
	return InterpreterAPIDeleteInterpreterContextRequest{
		ApiService: a,
		ctx: ctx,
		id: id,
	}
}

// Execute executes the request
//  @return map[string]string
func (a *InterpreterAPIService) DeleteInterpreterContextExecute(r InterpreterAPIDeleteInterpreterContextRequest) (map[string]string, *http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodDelete
		localVarPostBody     interface{}
		formFiles            []formFile
		localVarReturnValue  map[string]string
	)

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

	localVarPath := localBasePath + "/process/interpreter/context/{id}"
	localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -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{"application/json"}

	// 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 := 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,
		}
		if localVarHTTPResponse.StatusCode == 400 {
			var v map[string]string
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarReturnValue, localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarReturnValue, localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 404 {
			var v map[string]string
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarReturnValue, localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
		}
		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 InterpreterAPIExecuteInterpreterCodeRequest struct {
	ctx context.Context
	ApiService InterpreterAPI
}

func (r InterpreterAPIExecuteInterpreterCodeRequest) Execute() (*http.Response, error) {
	return r.ApiService.ExecuteInterpreterCodeExecute(r)
}

/*
ExecuteInterpreterCode Execute code in an interpreter context

Executes code in a specified context (or default context if not specified) via WebSocket streaming

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

// Execute executes the request
func (a *InterpreterAPIService) ExecuteInterpreterCodeExecute(r InterpreterAPIExecuteInterpreterCodeRequest) (*http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     interface{}
		formFiles            []formFile
	)

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

	localVarPath := localBasePath + "/process/interpreter/execute"

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

	// 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 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 InterpreterAPIListInterpreterContextsRequest struct {
	ctx context.Context
	ApiService InterpreterAPI
}

func (r InterpreterAPIListInterpreterContextsRequest) Execute() (*ListContextsResponse, *http.Response, error) {
	return r.ApiService.ListInterpreterContextsExecute(r)
}

/*
ListInterpreterContexts List all user-created interpreter contexts

Returns information about all user-created interpreter contexts (excludes default context)

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

// Execute executes the request
//  @return ListContextsResponse
func (a *InterpreterAPIService) ListInterpreterContextsExecute(r InterpreterAPIListInterpreterContextsRequest) (*ListContextsResponse, *http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     interface{}
		formFiles            []formFile
		localVarReturnValue  *ListContextsResponse
	)

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

	localVarPath := localBasePath + "/process/interpreter/context"

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

	// 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 := 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
}
