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


type IoTManagerInternalAPIAPI interface {

	/*
	IoTManagerInternalCheckHealth Get health status of service

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

	// IoTManagerInternalCheckHealthExecute executes the request
	IoTManagerInternalCheckHealthExecute(r ApiIoTManagerInternalCheckHealthRequest) (*http.Response, error)

	/*
	IoTManagerInternalCheckLiveliness Get service liveliness status.

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

	// IoTManagerInternalCheckLivelinessExecute executes the request
	IoTManagerInternalCheckLivelinessExecute(r ApiIoTManagerInternalCheckLivelinessRequest) (*http.Response, error)

	/*
	IoTManagerInternalDecommissionDevice Remove a device from Iot Hub.

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param tenantId ID of tenant the device belongs to.
	@param deviceId ID of the target device.
	@return ApiIoTManagerInternalDecommissionDeviceRequest
	*/
	IoTManagerInternalDecommissionDevice(ctx context.Context, tenantId string, deviceId string) ApiIoTManagerInternalDecommissionDeviceRequest

	// IoTManagerInternalDecommissionDeviceExecute executes the request
	IoTManagerInternalDecommissionDeviceExecute(r ApiIoTManagerInternalDecommissionDeviceRequest) (*http.Response, error)

	/*
	IoTManagerInternalDeleteTenant Delete all data belonging to a given tenant.

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param tenantId ID of tenant to remove.
	@return ApiIoTManagerInternalDeleteTenantRequest
	*/
	IoTManagerInternalDeleteTenant(ctx context.Context, tenantId string) ApiIoTManagerInternalDeleteTenantRequest

	// IoTManagerInternalDeleteTenantExecute executes the request
	IoTManagerInternalDeleteTenantExecute(r ApiIoTManagerInternalDeleteTenantRequest) (*http.Response, error)

	/*
	IoTManagerInternalProvisionDevice Register a new device with the deviceconfig service.

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param tenantId ID of tenant the device belongs to.
	@return ApiIoTManagerInternalProvisionDeviceRequest
	*/
	IoTManagerInternalProvisionDevice(ctx context.Context, tenantId string) ApiIoTManagerInternalProvisionDeviceRequest

	// IoTManagerInternalProvisionDeviceExecute executes the request
	IoTManagerInternalProvisionDeviceExecute(r ApiIoTManagerInternalProvisionDeviceRequest) (*http.Response, error)

	/*
	IoTManagerInternalUpdateDeviceStatuses Update device statuses in bulk.

	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
	@param tenantId ID of tenant the device belongs to.
	@param status The status of the device
	@return ApiIoTManagerInternalUpdateDeviceStatusesRequest
	*/
	IoTManagerInternalUpdateDeviceStatuses(ctx context.Context, tenantId string, status string) ApiIoTManagerInternalUpdateDeviceStatusesRequest

	// IoTManagerInternalUpdateDeviceStatusesExecute executes the request
	IoTManagerInternalUpdateDeviceStatusesExecute(r ApiIoTManagerInternalUpdateDeviceStatusesRequest) (*http.Response, error)
}

// IoTManagerInternalAPIAPIService IoTManagerInternalAPIAPI service
type IoTManagerInternalAPIAPIService service

type ApiIoTManagerInternalCheckHealthRequest struct {
	ctx context.Context
	ApiService IoTManagerInternalAPIAPI
}

func (r ApiIoTManagerInternalCheckHealthRequest) Execute() (*http.Response, error) {
	return r.ApiService.IoTManagerInternalCheckHealthExecute(r)
}

/*
IoTManagerInternalCheckHealth Get health status of service

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

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

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

	localVarPath := localBasePath + "/api/internal/v1/iot-manager/health"

	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 == 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 ApiIoTManagerInternalCheckLivelinessRequest struct {
	ctx context.Context
	ApiService IoTManagerInternalAPIAPI
}

func (r ApiIoTManagerInternalCheckLivelinessRequest) Execute() (*http.Response, error) {
	return r.ApiService.IoTManagerInternalCheckLivelinessExecute(r)
}

/*
IoTManagerInternalCheckLiveliness Get service liveliness status.

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

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

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

	localVarPath := localBasePath + "/api/internal/v1/iot-manager/alive"

	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 == 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 ApiIoTManagerInternalDecommissionDeviceRequest struct {
	ctx context.Context
	ApiService IoTManagerInternalAPIAPI
	tenantId string
	deviceId string
}

func (r ApiIoTManagerInternalDecommissionDeviceRequest) Execute() (*http.Response, error) {
	return r.ApiService.IoTManagerInternalDecommissionDeviceExecute(r)
}

/*
IoTManagerInternalDecommissionDevice Remove a device from Iot Hub.

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param tenantId ID of tenant the device belongs to.
 @param deviceId ID of the target device.
 @return ApiIoTManagerInternalDecommissionDeviceRequest
*/
func (a *IoTManagerInternalAPIAPIService) IoTManagerInternalDecommissionDevice(ctx context.Context, tenantId string, deviceId string) ApiIoTManagerInternalDecommissionDeviceRequest {
	return ApiIoTManagerInternalDecommissionDeviceRequest{
		ApiService: a,
		ctx: ctx,
		tenantId: tenantId,
		deviceId: deviceId,
	}
}

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

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

	localVarPath := localBasePath + "/api/internal/v1/iot-manager/tenants/{tenantId}/devices/{deviceId}"
	localVarPath = strings.Replace(localVarPath, "{"+"tenantId"+"}", url.PathEscape(parameterValueToString(r.tenantId, "tenantId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"deviceId"+"}", url.PathEscape(parameterValueToString(r.deviceId, "deviceId")), -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 == 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 ApiIoTManagerInternalDeleteTenantRequest struct {
	ctx context.Context
	ApiService IoTManagerInternalAPIAPI
	tenantId string
}

func (r ApiIoTManagerInternalDeleteTenantRequest) Execute() (*http.Response, error) {
	return r.ApiService.IoTManagerInternalDeleteTenantExecute(r)
}

/*
IoTManagerInternalDeleteTenant Delete all data belonging to a given tenant.

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param tenantId ID of tenant to remove.
 @return ApiIoTManagerInternalDeleteTenantRequest
*/
func (a *IoTManagerInternalAPIAPIService) IoTManagerInternalDeleteTenant(ctx context.Context, tenantId string) ApiIoTManagerInternalDeleteTenantRequest {
	return ApiIoTManagerInternalDeleteTenantRequest{
		ApiService: a,
		ctx: ctx,
		tenantId: tenantId,
	}
}

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

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

	localVarPath := localBasePath + "/api/internal/v1/iot-manager/tenants/{tenantId}"
	localVarPath = strings.Replace(localVarPath, "{"+"tenantId"+"}", url.PathEscape(parameterValueToString(r.tenantId, "tenantId")), -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 == 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 ApiIoTManagerInternalProvisionDeviceRequest struct {
	ctx context.Context
	ApiService IoTManagerInternalAPIAPI
	tenantId string
	newDeviceInternalProvision *NewDeviceInternalProvision
}

func (r ApiIoTManagerInternalProvisionDeviceRequest) NewDeviceInternalProvision(newDeviceInternalProvision NewDeviceInternalProvision) ApiIoTManagerInternalProvisionDeviceRequest {
	r.newDeviceInternalProvision = &newDeviceInternalProvision
	return r
}

func (r ApiIoTManagerInternalProvisionDeviceRequest) Execute() (*http.Response, error) {
	return r.ApiService.IoTManagerInternalProvisionDeviceExecute(r)
}

/*
IoTManagerInternalProvisionDevice Register a new device with the deviceconfig service.

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param tenantId ID of tenant the device belongs to.
 @return ApiIoTManagerInternalProvisionDeviceRequest
*/
func (a *IoTManagerInternalAPIAPIService) IoTManagerInternalProvisionDevice(ctx context.Context, tenantId string) ApiIoTManagerInternalProvisionDeviceRequest {
	return ApiIoTManagerInternalProvisionDeviceRequest{
		ApiService: a,
		ctx: ctx,
		tenantId: tenantId,
	}
}

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

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

	localVarPath := localBasePath + "/api/internal/v1/iot-manager/tenants/{tenantId}/devices"
	localVarPath = strings.Replace(localVarPath, "{"+"tenantId"+"}", url.PathEscape(parameterValueToString(r.tenantId, "tenantId")), -1)

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := url.Values{}
	localVarFormParams := url.Values{}
	if r.newDeviceInternalProvision == nil {
		return nil, reportError("newDeviceInternalProvision 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.newDeviceInternalProvision
	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 == 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 ApiIoTManagerInternalUpdateDeviceStatusesRequest struct {
	ctx context.Context
	ApiService IoTManagerInternalAPIAPI
	tenantId string
	status string
	ioTManagerInternalUpdateDeviceStatusesRequestInner *[]IoTManagerInternalUpdateDeviceStatusesRequestInner
}

func (r ApiIoTManagerInternalUpdateDeviceStatusesRequest) IoTManagerInternalUpdateDeviceStatusesRequestInner(ioTManagerInternalUpdateDeviceStatusesRequestInner []IoTManagerInternalUpdateDeviceStatusesRequestInner) ApiIoTManagerInternalUpdateDeviceStatusesRequest {
	r.ioTManagerInternalUpdateDeviceStatusesRequestInner = &ioTManagerInternalUpdateDeviceStatusesRequestInner
	return r
}

func (r ApiIoTManagerInternalUpdateDeviceStatusesRequest) Execute() (*http.Response, error) {
	return r.ApiService.IoTManagerInternalUpdateDeviceStatusesExecute(r)
}

/*
IoTManagerInternalUpdateDeviceStatuses Update device statuses in bulk.

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @param tenantId ID of tenant the device belongs to.
 @param status The status of the device
 @return ApiIoTManagerInternalUpdateDeviceStatusesRequest
*/
func (a *IoTManagerInternalAPIAPIService) IoTManagerInternalUpdateDeviceStatuses(ctx context.Context, tenantId string, status string) ApiIoTManagerInternalUpdateDeviceStatusesRequest {
	return ApiIoTManagerInternalUpdateDeviceStatusesRequest{
		ApiService: a,
		ctx: ctx,
		tenantId: tenantId,
		status: status,
	}
}

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

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

	localVarPath := localBasePath + "/api/internal/v1/iot-manager/tenants/{tenantId}/bulk/devices/status/{status}"
	localVarPath = strings.Replace(localVarPath, "{"+"tenantId"+"}", url.PathEscape(parameterValueToString(r.tenantId, "tenantId")), -1)
	localVarPath = strings.Replace(localVarPath, "{"+"status"+"}", url.PathEscape(parameterValueToString(r.status, "status")), -1)

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := url.Values{}
	localVarFormParams := url.Values{}
	if r.ioTManagerInternalUpdateDeviceStatusesRequestInner == nil {
		return nil, reportError("ioTManagerInternalUpdateDeviceStatusesRequestInner 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.ioTManagerInternalUpdateDeviceStatusesRequestInner
	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 == 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
}
