// Package system provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT.
package system

import (
	"encoding/json"
	"fmt"

	core "github.com/meshery/schemas/models/core"
	connectionv1beta3 "github.com/meshery/schemas/models/v1beta3/connection"
	openapi_types "github.com/oapi-codegen/runtime/types"
)

// Defines values for ControllerDiagnosticController.
const (
	ControllerDiagnosticControllerBROKER   ControllerDiagnosticController = "BROKER"
	ControllerDiagnosticControllerMESHSYNC ControllerDiagnosticController = "MESHSYNC"
	ControllerDiagnosticControllerOPERATOR ControllerDiagnosticController = "OPERATOR"
)

// Defines values for ControllerDiagnosticSeverity.
const (
	Error   ControllerDiagnosticSeverity = "error"
	Info    ControllerDiagnosticSeverity = "info"
	Warning ControllerDiagnosticSeverity = "warning"
)

// Defines values for ControllerStatusController.
const (
	ControllerStatusControllerBROKER   ControllerStatusController = "BROKER"
	ControllerStatusControllerMESHSYNC ControllerStatusController = "MESHSYNC"
	ControllerStatusControllerOPERATOR ControllerStatusController = "OPERATOR"
)

// Defines values for ControllerStatusValue.
const (
	CONNECTED   ControllerStatusValue = "CONNECTED"
	DEPLOYED    ControllerStatusValue = "DEPLOYED"
	DEPLOYING   ControllerStatusValue = "DEPLOYING"
	ENABLED     ControllerStatusValue = "ENABLED"
	NOTDEPLOYED ControllerStatusValue = "NOTDEPLOYED"
	RUNNING     ControllerStatusValue = "RUNNING"
	UNDEPLOYED  ControllerStatusValue = "UNDEPLOYED"
	UNKOWN      ControllerStatusValue = "UNKOWN"
)

// AddKubernetesConfigPayload Multipart form payload for importing a kubeconfig. `contexts` and `selectedContexts` are JSON-encoded strings because they travel as multipart form fields alongside the file.
type AddKubernetesConfigPayload struct {
	// Contexts JSON-encoded object mapping a discovered context ID to per-context import options, e.g. `{"<contextId>": {"meshsyncDeploymentMode": "operator", "name": "my-cluster"}}`. `meshsyncDeploymentMode` selects how MeshSync runs for the resulting connection; `name` overrides the connection name.
	Contexts *string `json:"contexts,omitempty" yaml:"contexts,omitempty"`

	// K8sfile Kubeconfig file contents.
	K8sfile openapi_types.File `json:"k8sfile" yaml:"k8sfile"`

	// SelectedContexts JSON-encoded array of discovered context IDs to import. When absent, every context discovered in the kubeconfig is imported.
	SelectedContexts *string `json:"selectedContexts,omitempty" yaml:"selectedContexts,omitempty"`
}

// AddKubernetesConfigResponse Discovered kubeconfig contexts bucketed by import outcome. Every bucket is always present (empty when no context landed in it).
type AddKubernetesConfigResponse struct {
	// ConnectedContexts Contexts whose connection already exists in (or transitioned to) the connected state.
	ConnectedContexts []connectionv1beta3.K8sContext `json:"connectedContexts" yaml:"connectedContexts"`

	// ErroredContexts Contexts that could not be saved as connections. The failure detail is recorded in the emitted event's metadata, not on the context object.
	ErroredContexts []connectionv1beta3.K8sContext `json:"erroredContexts" yaml:"erroredContexts"`

	// IgnoredContexts Contexts whose connection is in the ignored state.
	IgnoredContexts []connectionv1beta3.K8sContext `json:"ignoredContexts" yaml:"ignoredContexts"`

	// RegisteredContexts Contexts newly registered as discovered connections.
	RegisteredContexts []connectionv1beta3.K8sContext `json:"registeredContexts" yaml:"registeredContexts"`
}

// ConnectionDiagnostics Diagnostics for a kubernetes connection's Meshery controllers, for rendering a "Diagnostics" section in the connection detail view.
type ConnectionDiagnostics struct {
	// ConnectionId A Universally Unique Identifier used to uniquely identify entities in Meshery. The UUID core definition is used across different schemas.
	ConnectionId core.Uuid `json:"connectionId" yaml:"connectionId"`

	// Diagnostics The diagnostics detected for this connection (possibly empty).
	Diagnostics []ControllerDiagnostic `json:"diagnostics" yaml:"diagnostics"`

	// Healthy True when no warning/error diagnostics were detected (informational diagnostics do not affect health).
	Healthy bool `json:"healthy" yaml:"healthy"`
}

// ControllerDiagnostic A single human-actionable diagnostic about a kubernetes connection's Meshery controllers, with an explanation and remediation steps.
type ControllerDiagnostic struct {
	// Code Stable machine-readable code for this diagnostic (e.g. `broker_unreachable`), for the UI to key on.
	Code string `json:"code" yaml:"code"`

	// Controller The controller this diagnostic concerns, when applicable.
	Controller *ControllerDiagnosticController `json:"controller,omitempty" yaml:"controller,omitempty"`

	// Description A fuller explanation of what is wrong and why.
	Description *string `json:"description,omitempty" yaml:"description,omitempty"`

	// Endpoint A relevant endpoint for the diagnostic, when applicable (e.g. the broker's published address the user needs to make reachable).
	Endpoint *string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`

	// Remediation Ordered, concrete steps the user can take to resolve the issue.
	Remediation *[]string `json:"remediation,omitempty" yaml:"remediation,omitempty"`

	// Severity How serious the diagnostic is.
	Severity ControllerDiagnosticSeverity `json:"severity" yaml:"severity"`

	// Summary Short, human-readable title for the diagnostic.
	Summary string `json:"summary" yaml:"summary"`
}

// ControllerDiagnosticController The controller this diagnostic concerns, when applicable.
type ControllerDiagnosticController string

// ControllerDiagnosticSeverity How serious the diagnostic is.
type ControllerDiagnosticSeverity string

// ControllerInfo Detailed status of a named Meshery controller (MeshSync or Broker) for a kubernetes connection.
type ControllerInfo struct {
	// ConnectionId A Universally Unique Identifier used to uniquely identify entities in Meshery. The UUID core definition is used across different schemas.
	ConnectionId core.Uuid `json:"connectionId" yaml:"connectionId"`

	// Name Controller name (e.g. MeshSync, MesheryBroker).
	Name string `json:"name" yaml:"name"`

	// Status Current controller status. May be composed, e.g. "Connected <endpoint>".
	Status string `json:"status" yaml:"status"`

	// Version Deployed controller version, when known.
	Version string `json:"version" yaml:"version"`
}

// ControllerStatus Status of a single Meshery controller (operator, MeshSync, or broker) for a kubernetes connection. Element type of the controller-status SSE stream and the operator status response.
type ControllerStatus struct {
	// ConnectionId A Universally Unique Identifier used to uniquely identify entities in Meshery. The UUID core definition is used across different schemas.
	ConnectionId core.Uuid `json:"connectionId" yaml:"connectionId"`

	// Controller The controller this status describes.
	Controller ControllerStatusController `json:"controller" yaml:"controller"`

	// Status Current status of a single Meshery controller (operator, MeshSync, or broker). Mirrors the MesheryControllerStatus GraphQL enum (server/internal/graphql/schema/schema.graphql) during the ongoing migration of controller-status consumers from GraphQL to this REST API; the literal values (including the published "UNKOWN" spelling) are load-bearing and must not be changed independently of that enum.
	Status ControllerStatusValue `json:"status" yaml:"status"`

	// Version Deployed controller version, when known.
	Version string `json:"version" yaml:"version"`
}

// ControllerStatusController The controller this status describes.
type ControllerStatusController string

// ControllerStatusValue Current status of a single Meshery controller (operator, MeshSync, or broker). Mirrors the MesheryControllerStatus GraphQL enum (server/internal/graphql/schema/schema.graphql) during the ongoing migration of controller-status consumers from GraphQL to this REST API; the literal values (including the published "UNKOWN" spelling) are load-bearing and must not be changed independently of that enum.
type ControllerStatusValue string

// DiscoverKubernetesContextsPayload Multipart form payload for kubeconfig context discovery.
type DiscoverKubernetesContextsPayload struct {
	// K8sfile Kubeconfig file contents.
	K8sfile openapi_types.File `json:"k8sfile" yaml:"k8sfile"`
}

// EmailTestRequest Request body for sending a test email through the configured SMTP provider.
type EmailTestRequest struct {
	// Subject Subject line for the test message. A default subject is used when omitted.
	Subject *string `json:"subject,omitempty" yaml:"subject,omitempty"`

	// To Recipient email address for the test message.
	To openapi_types.Email `json:"to" yaml:"to"`
}

// EmailTestResponse Result of a test email send attempt.
type EmailTestResponse struct {
	// Message Human-readable result message.
	Message string `json:"message" yaml:"message"`

	// SentTo Recipient address the test email was sent to.
	SentTo openapi_types.Email `json:"sentTo" yaml:"sentTo"`

	// Status Outcome status of the send attempt (e.g. `success`).
	Status string `json:"status" yaml:"status"`

	// Timestamp Unix-epoch seconds, as a decimal string, when the test email was sent.
	Timestamp string `json:"timestamp" yaml:"timestamp"`
}

// KubernetesPingResponse Result of pinging a Kubernetes connection's API server.
type KubernetesPingResponse struct {
	// ServerVersion Version string reported by the cluster's API server. The wire field is `server_version` - this endpoint's published wire casing predates the camelCase convention and is preserved within this API version.
	ServerVersion string `json:"server_version" yaml:"server_version"`
}

// SystemDatabaseSummary Paginated summary of the Meshery server's embedded database.
type SystemDatabaseSummary struct {
	// Page Zero-based page index of the returned table slice.
	Page int `json:"page" yaml:"page"`

	// PageSize Number of tables included in this page.
	PageSize int `json:"pageSize" yaml:"pageSize"`

	// RecordCount Aggregate row count across the tables returned in this page.
	RecordCount int `json:"recordCount" yaml:"recordCount"`

	// Tables Tables included in this page, with per-table row counts.
	Tables []SystemDatabaseTable `json:"tables" yaml:"tables"`

	// TotalTables Total number of tables in the database matching the search filter.
	TotalTables int `json:"totalTables" yaml:"totalTables"`
}

// SystemDatabaseTable Database table summary.
type SystemDatabaseTable struct {
	// Count Number of rows currently in the table.
	Count int64 `json:"count" yaml:"count"`

	// Name Name of the table.
	Name string `json:"name" yaml:"name"`

	// Type SQLite object type (e.g. `table`).
	Type string `json:"type" yaml:"type"`
}

// SystemMessageResponse Status message response.
type SystemMessageResponse struct {
	// Message Human-readable status message.
	Message string `json:"message" yaml:"message"`
}

// SystemSessionSync Session bootstrap payload for the authenticated user.
type SystemSessionSync struct {
	// K8sConfig Kubernetes contexts currently tracked by the Meshery server.
	K8sConfig            *[]SystemSessionSyncK8sContext `json:"k8sConfig,omitempty" yaml:"k8sConfig,omitempty"`
	AdditionalProperties map[string]interface{}         `json:"-" yaml:"-"`
}

// SystemSessionSyncK8sContext Kubernetes context tracked by Meshery.
type SystemSessionSyncK8sContext struct {
	// ClusterConfigured True when Meshery has a usable kubeconfig for this context.
	ClusterConfigured *bool `json:"clusterConfigured,omitempty" yaml:"clusterConfigured,omitempty"`

	// ClusterId A Universally Unique Identifier used to uniquely identify entities in Meshery. The UUID core definition is used across different schemas.
	ClusterId *core.Uuid `json:"clusterId,omitempty" yaml:"clusterId,omitempty"`

	// CreatedAt Timestamp when the resource was created.
	CreatedAt core.CreatedAt `db:"created_at" json:"createdAt,omitempty" yaml:"createdAt,omitempty"`

	// Id Stable identifier for the Kubernetes context.
	ID *string `json:"id,omitempty" yaml:"id,omitempty"`

	// Name Human-readable name of the Kubernetes context.
	Name *string `json:"name,omitempty" yaml:"name,omitempty"`

	// Server API server URL for the Kubernetes context.
	Server *string `json:"server,omitempty" yaml:"server,omitempty"`

	// UpdatedAt Timestamp when the resource was updated.
	UpdatedAt core.UpdatedAt `db:"updated_at" json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"`
}

// SystemVersion Version metadata for a running Meshery service.
type SystemVersion struct {
	// Build Build identifier (typically the git tag of the running binary).
	Build *string `json:"build,omitempty" yaml:"build,omitempty"`

	// Commitsha Git commit SHA of the running service. The wire field is `commitsha`.
	Commitsha *string `json:"commitsha,omitempty" yaml:"commitsha,omitempty"`

	// Latest Latest available Meshery release tag fetched from GitHub.
	Latest *string `json:"latest,omitempty" yaml:"latest,omitempty"`

	// Outdated True when the running build is older than the latest available release.
	Outdated *bool `json:"outdated,omitempty" yaml:"outdated,omitempty"`

	// ReleaseChannel Release channel of the running binary (e.g. `stable`, `edge`).
	ReleaseChannel *string `json:"releaseChannel,omitempty" yaml:"releaseChannel,omitempty"`

	// Version Meshery Cloud deployment version.
	Version *string `json:"version,omitempty" yaml:"version,omitempty"`
}

// Getter for additional properties for SystemSessionSync. Returns the specified
// element and whether it was found
func (a SystemSessionSync) Get(fieldName string) (value interface{}, found bool) {
	if a.AdditionalProperties != nil {
		value, found = a.AdditionalProperties[fieldName]
	}
	return
}

// Setter for additional properties for SystemSessionSync
func (a *SystemSessionSync) Set(fieldName string, value interface{}) {
	if a.AdditionalProperties == nil {
		a.AdditionalProperties = make(map[string]interface{})
	}
	a.AdditionalProperties[fieldName] = value
}

// Override default JSON handling for SystemSessionSync to handle AdditionalProperties
func (a *SystemSessionSync) UnmarshalJSON(b []byte) error {
	object := make(map[string]json.RawMessage)
	err := json.Unmarshal(b, &object)
	if err != nil {
		return err
	}

	if raw, found := object["k8sConfig"]; found {
		err = json.Unmarshal(raw, &a.K8sConfig)
		if err != nil {
			return fmt.Errorf("error reading 'k8sConfig': %w", err)
		}
		delete(object, "k8sConfig")
	}

	if len(object) != 0 {
		a.AdditionalProperties = make(map[string]interface{})
		for fieldName, fieldBuf := range object {
			var fieldVal interface{}
			err := json.Unmarshal(fieldBuf, &fieldVal)
			if err != nil {
				return fmt.Errorf("error unmarshaling field %s: %w", fieldName, err)
			}
			a.AdditionalProperties[fieldName] = fieldVal
		}
	}
	return nil
}

// Override default JSON handling for SystemSessionSync to handle AdditionalProperties
func (a SystemSessionSync) MarshalJSON() ([]byte, error) {
	var err error
	object := make(map[string]json.RawMessage)

	if a.K8sConfig != nil {
		object["k8sConfig"], err = json.Marshal(a.K8sConfig)
		if err != nil {
			return nil, fmt.Errorf("error marshaling 'k8sConfig': %w", err)
		}
	}

	for fieldName, field := range a.AdditionalProperties {
		object[fieldName], err = json.Marshal(field)
		if err != nil {
			return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err)
		}
	}
	return json.Marshal(object)
}
