namespace EntKube.Web.Services;
///
/// Abstraction over Kubernetes API operations that CnpgService needs.
/// Allows testing orchestration logic without real K8s clusters.
///
/// Implementations use the k8s .NET client or kubectl under the hood,
/// applying manifests (CNPG Cluster CRDs, Backup CRDs, Secrets) and
/// executing SQL via kubectl exec against the primary pod.
///
public interface IKubernetesClientFactory
{
///
/// Applies a YAML manifest to a Kubernetes cluster using the given kubeconfig.
/// Equivalent to "kubectl apply -f -" with the manifest piped in.
///
Task ApplyManifestAsync(string manifest, string kubeconfig, CancellationToken ct = default);
///
/// Deletes a specific Kubernetes resource by kind/name/namespace.
/// Equivalent to "kubectl delete {kind} {name} -n {namespace}".
///
Task DeleteManifestAsync(string kind, string name, string ns, string kubeconfig, CancellationToken ct = default);
///
/// Ensures a namespace exists, creating it if it doesn't.
/// Equivalent to "kubectl create namespace {ns} --dry-run=client -o yaml | kubectl apply -f -".
///
Task EnsureNamespaceAsync(string ns, string kubeconfig, CancellationToken ct = default);
///
/// Gets the JSON output of a kubectl command. Used for querying cluster/pod status.
///
Task GetJsonAsync(string resource, string ns, string kubeconfig, string labelSelector = "", CancellationToken ct = default);
///
/// Executes a SQL statement against the CNPG primary pod.
/// Uses kubectl exec to connect to the primary and run psql.
///
Task ExecuteSqlAsync(string clusterName, string ns, string sql, string kubeconfig, CancellationToken ct = default);
///
/// Executes a MongoDB script against the primary pod via kubectl exec + mongosh.
/// The primary pod is the first StatefulSet member: {clusterName}-0.
/// When username and password are provided, mongosh connects with SCRAM credentials.
///
Task ExecuteMongoAsync(string clusterName, string ns, string script, string kubeconfig,
string? username = null, string? password = null, CancellationToken ct = default);
///
/// Reads a single key from a Kubernetes Secret and returns the decoded value.
/// Returns null if the secret or key does not exist.
///
Task GetSecretValueAsync(string secretName, string key, string ns, string kubeconfig,
CancellationToken ct = default);
}