/*
Mender API

Combined API specification for the features of the different Mender backend services, suitable for code generation applications 

API version: 1
Contact: support@mender.io
*/

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

package client

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


type DeviceConnectManagementAPIAPI interface {

	/*
	DeviceConnectManagementCheckUpdate Trigger check-update for the Mender client running on the device

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

	// DeviceConnectManagementCheckUpdateExecute executes the request
	DeviceConnectManagementCheckUpdateExecute(r ApiDeviceConnectManagementCheckUpdateRequest) (*http.Response, error)

	/*
	DeviceConnectManagementConnect Establish permanent connection with device

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

	// DeviceConnectManagementConnectExecute executes the request
	DeviceConnectManagementConnectExecute(r ApiDeviceConnectManagementConnectRequest) (*http.Response, error)

	/*
	DeviceConnectManagementDownload Download a file from the device

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

	// DeviceConnectManagementDownloadExecute executes the request
	//  @return *os.File
	DeviceConnectManagementDownloadExecute(r ApiDeviceConnectManagementDownloadRequest) (*os.File, *http.Response, error)

	/*
	DeviceConnectManagementGetDevice Fetch the state of a device.

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

	// DeviceConnectManagementGetDeviceExecute executes the request
	//  @return ConnectionState
	DeviceConnectManagementGetDeviceExecute(r ApiDeviceConnectManagementGetDeviceRequest) (*ConnectionState, *http.Response, error)

	/*
	DeviceConnectManagementPlayback Establish a connection for playing back a session

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param sessionId ID for the session to play back.
	@return ApiDeviceConnectManagementPlaybackRequest
	*/
	DeviceConnectManagementPlayback(ctx context.Context, sessionId string) ApiDeviceConnectManagementPlaybackRequest

	// DeviceConnectManagementPlaybackExecute executes the request
	DeviceConnectManagementPlaybackExecute(r ApiDeviceConnectManagementPlaybackRequest) (*http.Response, error)

	/*
	DeviceConnectManagementSendInventory Trigger send-inventory for the Mender client running on the device

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

	// DeviceConnectManagementSendInventoryExecute executes the request
	DeviceConnectManagementSendInventoryExecute(r ApiDeviceConnectManagementSendInventoryRequest) (*http.Response, error)

	/*
	DeviceConnectManagementUpload Upload a file to the device

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

	// DeviceConnectManagementUploadExecute executes the request
	DeviceConnectManagementUploadExecute(r ApiDeviceConnectManagementUploadRequest) (*http.Response, error)
}

// DeviceConnectManagementAPIAPIService DeviceConnectManagementAPIAPI service
type DeviceConnectManagementAPIAPIService service

type ApiDeviceConnectManagementCheckUpdateRequest struct {
	ctx context.Context
	ApiService DeviceConnectManagementAPIAPI
	id string
}

func (r ApiDeviceConnectManagementCheckUpdateRequest) Execute() (*http.Response, error) {
	return r.ApiService.DeviceConnectManagementCheckUpdateExecute(r)
}

/*
DeviceConnectManagementCheckUpdate Trigger check-update for the Mender client running on the device

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param id ID of the device.
 @return ApiDeviceConnectManagementCheckUpdateRequest
*/
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementCheckUpdate(ctx context.Context, id string) ApiDeviceConnectManagementCheckUpdateRequest {
	return ApiDeviceConnectManagementCheckUpdateRequest{
		ApiService: a,
		ctx: ctx,
		id: id,
	}
}

// Execute executes the request
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementCheckUpdateExecute(r ApiDeviceConnectManagementCheckUpdateRequest) (*http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodPost
		localVarPostBody     interface{}
		formFiles            []formFile
	)

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

	localVarPath := localBasePath + "/api/management/v1/deviceconnect/devices/{id}/check-update"
	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 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 a.client.cfg.ResponseMiddleware != nil {
		err = a.client.cfg.ResponseMiddleware(localVarHTTPResponse, localVarBody)
		if err != nil {
			return localVarHTTPResponse, err
		}
	}

	if localVarHTTPResponse.StatusCode >= 300 {
		newErr := &GenericOpenAPIError{
			body:  localVarBody,
			error: localVarHTTPResponse.Status,
		}
		if localVarHTTPResponse.StatusCode == 400 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 404 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 409 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 500 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
		}
		return localVarHTTPResponse, newErr
	}

	return localVarHTTPResponse, nil
}

type ApiDeviceConnectManagementConnectRequest struct {
	ctx context.Context
	ApiService DeviceConnectManagementAPIAPI
	id string
	connection *string
	upgrade *string
	secWebsocketKey *string
	secWebsocketVersion *int32
}

// Standard websocket request header.
func (r ApiDeviceConnectManagementConnectRequest) Connection(connection string) ApiDeviceConnectManagementConnectRequest {
	r.connection = &connection
	return r
}

// Standard websocket request header.
func (r ApiDeviceConnectManagementConnectRequest) Upgrade(upgrade string) ApiDeviceConnectManagementConnectRequest {
	r.upgrade = &upgrade
	return r
}

// Standard websocket request header.
func (r ApiDeviceConnectManagementConnectRequest) SecWebsocketKey(secWebsocketKey string) ApiDeviceConnectManagementConnectRequest {
	r.secWebsocketKey = &secWebsocketKey
	return r
}

// Standard websocket request header.
func (r ApiDeviceConnectManagementConnectRequest) SecWebsocketVersion(secWebsocketVersion int32) ApiDeviceConnectManagementConnectRequest {
	r.secWebsocketVersion = &secWebsocketVersion
	return r
}

func (r ApiDeviceConnectManagementConnectRequest) Execute() (*http.Response, error) {
	return r.ApiService.DeviceConnectManagementConnectExecute(r)
}

/*
DeviceConnectManagementConnect Establish permanent connection with device

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param id ID of the device.
 @return ApiDeviceConnectManagementConnectRequest
*/
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementConnect(ctx context.Context, id string) ApiDeviceConnectManagementConnectRequest {
	return ApiDeviceConnectManagementConnectRequest{
		ApiService: a,
		ctx: ctx,
		id: id,
	}
}

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

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

	localVarPath := localBasePath + "/api/management/v1/deviceconnect/devices/{id}/connect"
	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
	}
	if r.connection != nil {
		parameterAddToHeaderOrQuery(localVarHeaderParams, "Connection", r.connection, "simple", "")
	}
	if r.upgrade != nil {
		parameterAddToHeaderOrQuery(localVarHeaderParams, "Upgrade", r.upgrade, "simple", "")
	}
	if r.secWebsocketKey != nil {
		parameterAddToHeaderOrQuery(localVarHeaderParams, "Sec-Websocket-Key", r.secWebsocketKey, "simple", "")
	}
	if r.secWebsocketVersion != nil {
		parameterAddToHeaderOrQuery(localVarHeaderParams, "Sec-Websocket-Version", r.secWebsocketVersion, "simple", "")
	}
	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 a.client.cfg.ResponseMiddleware != nil {
		err = a.client.cfg.ResponseMiddleware(localVarHTTPResponse, localVarBody)
		if err != nil {
			return localVarHTTPResponse, err
		}
	}

	if localVarHTTPResponse.StatusCode >= 300 {
		newErr := &GenericOpenAPIError{
			body:  localVarBody,
			error: localVarHTTPResponse.Status,
		}
		if localVarHTTPResponse.StatusCode == 400 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 404 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 500 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
		}
		return localVarHTTPResponse, newErr
	}

	return localVarHTTPResponse, nil
}

type ApiDeviceConnectManagementDownloadRequest struct {
	ctx context.Context
	ApiService DeviceConnectManagementAPIAPI
	id string
	path *string
}

// Path of the file on the device.
func (r ApiDeviceConnectManagementDownloadRequest) Path(path string) ApiDeviceConnectManagementDownloadRequest {
	r.path = &path
	return r
}

func (r ApiDeviceConnectManagementDownloadRequest) Execute() (*os.File, *http.Response, error) {
	return r.ApiService.DeviceConnectManagementDownloadExecute(r)
}

/*
DeviceConnectManagementDownload Download a file from the device

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param id ID of the device.
 @return ApiDeviceConnectManagementDownloadRequest
*/
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementDownload(ctx context.Context, id string) ApiDeviceConnectManagementDownloadRequest {
	return ApiDeviceConnectManagementDownloadRequest{
		ApiService: a,
		ctx: ctx,
		id: id,
	}
}

// Execute executes the request
//  @return *os.File
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementDownloadExecute(r ApiDeviceConnectManagementDownloadRequest) (*os.File, *http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     interface{}
		formFiles            []formFile
		localVarReturnValue  *os.File
	)

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

	localVarPath := localBasePath + "/api/management/v1/deviceconnect/devices/{id}/download"
	localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1)

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

	parameterAddToHeaderOrQuery(localVarQueryParams, "path", r.path, "form", "")
	// 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/octet-stream", "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 a.client.cfg.ResponseMiddleware != nil {
		err = a.client.cfg.ResponseMiddleware(localVarHTTPResponse, 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 Error
			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 Error
			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 == 409 {
			var v Error
			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 Error
			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 ApiDeviceConnectManagementGetDeviceRequest struct {
	ctx context.Context
	ApiService DeviceConnectManagementAPIAPI
	id string
}

func (r ApiDeviceConnectManagementGetDeviceRequest) Execute() (*ConnectionState, *http.Response, error) {
	return r.ApiService.DeviceConnectManagementGetDeviceExecute(r)
}

/*
DeviceConnectManagementGetDevice Fetch the state of a device.

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param id ID of the device.
 @return ApiDeviceConnectManagementGetDeviceRequest
*/
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementGetDevice(ctx context.Context, id string) ApiDeviceConnectManagementGetDeviceRequest {
	return ApiDeviceConnectManagementGetDeviceRequest{
		ApiService: a,
		ctx: ctx,
		id: id,
	}
}

// Execute executes the request
//  @return ConnectionState
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementGetDeviceExecute(r ApiDeviceConnectManagementGetDeviceRequest) (*ConnectionState, *http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     interface{}
		formFiles            []formFile
		localVarReturnValue  *ConnectionState
	)

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

	localVarPath := localBasePath + "/api/management/v1/deviceconnect/devices/{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 a.client.cfg.ResponseMiddleware != nil {
		err = a.client.cfg.ResponseMiddleware(localVarHTTPResponse, 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 Error
			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 Error
			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 Error
			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 ApiDeviceConnectManagementPlaybackRequest struct {
	ctx context.Context
	ApiService DeviceConnectManagementAPIAPI
	sessionId string
	sleepMs *int32
	connection *string
	upgrade *string
	secWebsocketKey *string
	secWebsocketVersion *int32
}

// Time in millisconds to sleep between the subsequent playback data writes.
func (r ApiDeviceConnectManagementPlaybackRequest) SleepMs(sleepMs int32) ApiDeviceConnectManagementPlaybackRequest {
	r.sleepMs = &sleepMs
	return r
}

// Standard websocket request header.
func (r ApiDeviceConnectManagementPlaybackRequest) Connection(connection string) ApiDeviceConnectManagementPlaybackRequest {
	r.connection = &connection
	return r
}

// Standard websocket request header.
func (r ApiDeviceConnectManagementPlaybackRequest) Upgrade(upgrade string) ApiDeviceConnectManagementPlaybackRequest {
	r.upgrade = &upgrade
	return r
}

// Standard websocket request header.
func (r ApiDeviceConnectManagementPlaybackRequest) SecWebsocketKey(secWebsocketKey string) ApiDeviceConnectManagementPlaybackRequest {
	r.secWebsocketKey = &secWebsocketKey
	return r
}

// Standard websocket request header.
func (r ApiDeviceConnectManagementPlaybackRequest) SecWebsocketVersion(secWebsocketVersion int32) ApiDeviceConnectManagementPlaybackRequest {
	r.secWebsocketVersion = &secWebsocketVersion
	return r
}

func (r ApiDeviceConnectManagementPlaybackRequest) Execute() (*http.Response, error) {
	return r.ApiService.DeviceConnectManagementPlaybackExecute(r)
}

/*
DeviceConnectManagementPlayback Establish a connection for playing back a session

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param sessionId ID for the session to play back.
 @return ApiDeviceConnectManagementPlaybackRequest
*/
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementPlayback(ctx context.Context, sessionId string) ApiDeviceConnectManagementPlaybackRequest {
	return ApiDeviceConnectManagementPlaybackRequest{
		ApiService: a,
		ctx: ctx,
		sessionId: sessionId,
	}
}

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

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

	localVarPath := localBasePath + "/api/management/v1/deviceconnect/sessions/{session_id}/playback"
	localVarPath = strings.Replace(localVarPath, "{"+"session_id"+"}", url.PathEscape(parameterValueToString(r.sessionId, "sessionId")), -1)

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

	if r.sleepMs != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "sleep_ms", r.sleepMs, "form", "")
	}
	// 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
	}
	if r.connection != nil {
		parameterAddToHeaderOrQuery(localVarHeaderParams, "Connection", r.connection, "simple", "")
	}
	if r.upgrade != nil {
		parameterAddToHeaderOrQuery(localVarHeaderParams, "Upgrade", r.upgrade, "simple", "")
	}
	if r.secWebsocketKey != nil {
		parameterAddToHeaderOrQuery(localVarHeaderParams, "Sec-Websocket-Key", r.secWebsocketKey, "simple", "")
	}
	if r.secWebsocketVersion != nil {
		parameterAddToHeaderOrQuery(localVarHeaderParams, "Sec-Websocket-Version", r.secWebsocketVersion, "simple", "")
	}
	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 a.client.cfg.ResponseMiddleware != nil {
		err = a.client.cfg.ResponseMiddleware(localVarHTTPResponse, localVarBody)
		if err != nil {
			return localVarHTTPResponse, err
		}
	}

	if localVarHTTPResponse.StatusCode >= 300 {
		newErr := &GenericOpenAPIError{
			body:  localVarBody,
			error: localVarHTTPResponse.Status,
		}
		if localVarHTTPResponse.StatusCode == 400 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 404 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 500 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
		}
		return localVarHTTPResponse, newErr
	}

	return localVarHTTPResponse, nil
}

type ApiDeviceConnectManagementSendInventoryRequest struct {
	ctx context.Context
	ApiService DeviceConnectManagementAPIAPI
	id string
}

func (r ApiDeviceConnectManagementSendInventoryRequest) Execute() (*http.Response, error) {
	return r.ApiService.DeviceConnectManagementSendInventoryExecute(r)
}

/*
DeviceConnectManagementSendInventory Trigger send-inventory for the Mender client running on the device

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param id ID of the device.
 @return ApiDeviceConnectManagementSendInventoryRequest
*/
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementSendInventory(ctx context.Context, id string) ApiDeviceConnectManagementSendInventoryRequest {
	return ApiDeviceConnectManagementSendInventoryRequest{
		ApiService: a,
		ctx: ctx,
		id: id,
	}
}

// Execute executes the request
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementSendInventoryExecute(r ApiDeviceConnectManagementSendInventoryRequest) (*http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodPost
		localVarPostBody     interface{}
		formFiles            []formFile
	)

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

	localVarPath := localBasePath + "/api/management/v1/deviceconnect/devices/{id}/send-inventory"
	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 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 a.client.cfg.ResponseMiddleware != nil {
		err = a.client.cfg.ResponseMiddleware(localVarHTTPResponse, localVarBody)
		if err != nil {
			return localVarHTTPResponse, err
		}
	}

	if localVarHTTPResponse.StatusCode >= 300 {
		newErr := &GenericOpenAPIError{
			body:  localVarBody,
			error: localVarHTTPResponse.Status,
		}
		if localVarHTTPResponse.StatusCode == 400 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 404 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 409 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 500 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
		}
		return localVarHTTPResponse, newErr
	}

	return localVarHTTPResponse, nil
}

type ApiDeviceConnectManagementUploadRequest struct {
	ctx context.Context
	ApiService DeviceConnectManagementAPIAPI
	id string
	path *string
	uid *int32
	gid *int32
	mode *string
	file *os.File
}

// The destination path on the device
func (r ApiDeviceConnectManagementUploadRequest) Path(path string) ApiDeviceConnectManagementUploadRequest {
	r.path = &path
	return r
}

// The numerical UID of the file on the device
func (r ApiDeviceConnectManagementUploadRequest) Uid(uid int32) ApiDeviceConnectManagementUploadRequest {
	r.uid = &uid
	return r
}

// The numerical GID of the file on the device
func (r ApiDeviceConnectManagementUploadRequest) Gid(gid int32) ApiDeviceConnectManagementUploadRequest {
	r.gid = &gid
	return r
}

// The octal representation of the mode of the file on the device
func (r ApiDeviceConnectManagementUploadRequest) Mode(mode string) ApiDeviceConnectManagementUploadRequest {
	r.mode = &mode
	return r
}

func (r ApiDeviceConnectManagementUploadRequest) File(file *os.File) ApiDeviceConnectManagementUploadRequest {
	r.file = file
	return r
}

func (r ApiDeviceConnectManagementUploadRequest) Execute() (*http.Response, error) {
	return r.ApiService.DeviceConnectManagementUploadExecute(r)
}

/*
DeviceConnectManagementUpload Upload a file to the device

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param id ID of the device.
 @return ApiDeviceConnectManagementUploadRequest
*/
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementUpload(ctx context.Context, id string) ApiDeviceConnectManagementUploadRequest {
	return ApiDeviceConnectManagementUploadRequest{
		ApiService: a,
		ctx: ctx,
		id: id,
	}
}

// Execute executes the request
func (a *DeviceConnectManagementAPIAPIService) DeviceConnectManagementUploadExecute(r ApiDeviceConnectManagementUploadRequest) (*http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodPut
		localVarPostBody     interface{}
		formFiles            []formFile
	)

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

	localVarPath := localBasePath + "/api/management/v1/deviceconnect/devices/{id}/upload"
	localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1)

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

	// to determine the Content-Type header
	localVarHTTPContentTypes := []string{"multipart/form-data"}

	// 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
	}
	parameterAddToHeaderOrQuery(localVarFormParams, "path", r.path, "", "")
	if r.uid != nil {
		parameterAddToHeaderOrQuery(localVarFormParams, "uid", r.uid, "", "")
	}
	if r.gid != nil {
		parameterAddToHeaderOrQuery(localVarFormParams, "gid", r.gid, "", "")
	}
	if r.mode != nil {
		parameterAddToHeaderOrQuery(localVarFormParams, "mode", r.mode, "", "")
	}
	var fileLocalVarFormFileName string
	var fileLocalVarFileName     string
	var fileLocalVarFileBytes    []byte

	fileLocalVarFormFileName = "file"
	fileLocalVarFile := r.file

	if fileLocalVarFile != nil {
		fbs, _ := io.ReadAll(fileLocalVarFile)

		fileLocalVarFileBytes = fbs
		fileLocalVarFileName = fileLocalVarFile.Name()
		fileLocalVarFile.Close()
		formFiles = append(formFiles, formFile{fileBytes: fileLocalVarFileBytes, fileName: fileLocalVarFileName, formFileName: fileLocalVarFormFileName})
	}
	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 a.client.cfg.ResponseMiddleware != nil {
		err = a.client.cfg.ResponseMiddleware(localVarHTTPResponse, localVarBody)
		if err != nil {
			return localVarHTTPResponse, err
		}
	}

	if localVarHTTPResponse.StatusCode >= 300 {
		newErr := &GenericOpenAPIError{
			body:  localVarBody,
			error: localVarHTTPResponse.Status,
		}
		if localVarHTTPResponse.StatusCode == 400 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 404 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 409 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 500 {
			var v Error
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
		}
		return localVarHTTPResponse, newErr
	}

	return localVarHTTPResponse, nil
}
