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

// LogAPIService LogAPI service
type LogAPIService service

type ApiLogsGetRequest struct {
	ctx             context.Context
	ApiService      *LogAPIService
	cluster         *string
	namespace       *string
	componentType   *string
	projectName     *string
	modelId         *string
	modelName       *string
	versionId       *string
	predictionJobId *string
	containerName   *string
	prefix          *string
	follow          *string
	previous        *string
	sinceSeconds    *string
	sinceTime       *string
	timestamps      *string
	tailLines       *string
	limitBytes      *string
}

func (r ApiLogsGetRequest) Cluster(cluster string) ApiLogsGetRequest {
	r.cluster = &cluster
	return r
}

func (r ApiLogsGetRequest) Namespace(namespace string) ApiLogsGetRequest {
	r.namespace = &namespace
	return r
}

func (r ApiLogsGetRequest) ComponentType(componentType string) ApiLogsGetRequest {
	r.componentType = &componentType
	return r
}

func (r ApiLogsGetRequest) ProjectName(projectName string) ApiLogsGetRequest {
	r.projectName = &projectName
	return r
}

func (r ApiLogsGetRequest) ModelId(modelId string) ApiLogsGetRequest {
	r.modelId = &modelId
	return r
}

func (r ApiLogsGetRequest) ModelName(modelName string) ApiLogsGetRequest {
	r.modelName = &modelName
	return r
}

func (r ApiLogsGetRequest) VersionId(versionId string) ApiLogsGetRequest {
	r.versionId = &versionId
	return r
}

func (r ApiLogsGetRequest) PredictionJobId(predictionJobId string) ApiLogsGetRequest {
	r.predictionJobId = &predictionJobId
	return r
}

func (r ApiLogsGetRequest) ContainerName(containerName string) ApiLogsGetRequest {
	r.containerName = &containerName
	return r
}

func (r ApiLogsGetRequest) Prefix(prefix string) ApiLogsGetRequest {
	r.prefix = &prefix
	return r
}

func (r ApiLogsGetRequest) Follow(follow string) ApiLogsGetRequest {
	r.follow = &follow
	return r
}

func (r ApiLogsGetRequest) Previous(previous string) ApiLogsGetRequest {
	r.previous = &previous
	return r
}

func (r ApiLogsGetRequest) SinceSeconds(sinceSeconds string) ApiLogsGetRequest {
	r.sinceSeconds = &sinceSeconds
	return r
}

func (r ApiLogsGetRequest) SinceTime(sinceTime string) ApiLogsGetRequest {
	r.sinceTime = &sinceTime
	return r
}

func (r ApiLogsGetRequest) Timestamps(timestamps string) ApiLogsGetRequest {
	r.timestamps = &timestamps
	return r
}

func (r ApiLogsGetRequest) TailLines(tailLines string) ApiLogsGetRequest {
	r.tailLines = &tailLines
	return r
}

func (r ApiLogsGetRequest) LimitBytes(limitBytes string) ApiLogsGetRequest {
	r.limitBytes = &limitBytes
	return r
}

func (r ApiLogsGetRequest) Execute() (*http.Response, error) {
	return r.ApiService.LogsGetExecute(r)
}

/*
LogsGet Retrieve log from a container

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

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

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

	localVarPath := localBasePath + "/logs"

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

	if r.projectName != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "project_name", r.projectName, "")
	}
	if r.modelId != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "model_id", r.modelId, "")
	}
	if r.modelName != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "model_name", r.modelName, "")
	}
	if r.versionId != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "version_id", r.versionId, "")
	}
	if r.predictionJobId != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "prediction_job_id", r.predictionJobId, "")
	}
	parameterAddToHeaderOrQuery(localVarQueryParams, "cluster", r.cluster, "")
	parameterAddToHeaderOrQuery(localVarQueryParams, "namespace", r.namespace, "")
	parameterAddToHeaderOrQuery(localVarQueryParams, "component_type", r.componentType, "")
	if r.containerName != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "container_name", r.containerName, "")
	}
	if r.prefix != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "prefix", r.prefix, "")
	}
	if r.follow != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "follow", r.follow, "")
	}
	if r.previous != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "previous", r.previous, "")
	}
	if r.sinceSeconds != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "since_seconds", r.sinceSeconds, "")
	}
	if r.sinceTime != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "since_time", r.sinceTime, "")
	}
	if r.timestamps != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "timestamps", r.timestamps, "")
	}
	if r.tailLines != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "tail_lines", r.tailLines, "")
	}
	if r.limitBytes != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "limit_bytes", r.limitBytes, "")
	}
	// 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
}
