namespace EntKube.Web.Data;
///
/// An app deployment represents a deployable unit targeting a specific cluster
/// and namespace. Think of it like an ArgoCD Application — it describes what
/// should be deployed, where, and tracks whether the live state matches.
///
/// A deployment can be defined three ways:
/// - Manual: structured form (containers, services, PVCs) → generated manifests
/// - Yaml: raw K8s YAML pasted or uploaded
/// - HelmChart: a Helm chart with repo, name, version, and dynamic values
///
/// Regardless of type, the platform tracks the deployment's sync and health
/// status by comparing desired state to live cluster state.
///
public class AppDeployment
{
public Guid Id { get; set; }
public Guid AppId { get; set; }
///
/// A human-friendly name for this deployment (e.g. "billing-api-prod").
/// Must be unique within an app.
///
public required string Name { get; set; }
///
/// How this deployment is defined — Manual form, raw YAML, or Helm chart.
///
public DeploymentType Type { get; set; }
// ── Target ──
///
/// The environment this deployment targets (e.g. Production).
///
public Guid EnvironmentId { get; set; }
///
/// The cluster within that environment where resources will be applied.
///
public Guid ClusterId { get; set; }
///
/// The Kubernetes namespace for all resources in this deployment.
///
public required string Namespace { get; set; }
// ── Status (ArgoCD-style) ──
public SyncStatus SyncStatus { get; set; } = SyncStatus.Unknown;
public HealthStatus HealthStatus { get; set; } = HealthStatus.Unknown;
public string? StatusMessage { get; set; }
public DateTime? LastSyncedAt { get; set; }
// ── Helm-specific fields (only used when Type == HelmChart) ──
///
/// The Helm chart repository URL (e.g. "https://charts.bitnami.com/bitnami").
///
public string? HelmRepoUrl { get; set; }
///
/// The chart name within the repository (e.g. "postgresql").
///
public string? HelmChartName { get; set; }
///
/// The chart version to deploy (e.g. "15.5.0").
///
public string? HelmChartVersion { get; set; }
///
/// The Helm values as YAML text. These override the chart's default values.
/// Stored as free-form YAML so any chart's values can be represented.
///
public string? HelmValues { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
// ── Git source fields (only used when Type is GitYaml, GitHelm, or GitAppOfApps) ──
///
/// The URL of the Git repository to sync from. Used for policy-credential-based
/// git access (no GitRepository record required). Takes precedence over GitRepositoryId.
///
public string? GitUrl { get; set; }
///
/// Legacy: FK to a registered GitRepository. Superseded by GitUrl for new deployments.
///
public Guid? GitRepositoryId { get; set; }
///
/// Path within the repository to the manifest directory, Helm chart root,
/// or app-of-apps directory. Use "." for the repo root.
///
public string? GitPath { get; set; }
///
/// Branch, tag, or commit SHA to check out. Defaults to the repository's
/// DefaultBranch when null.
///
public string? GitRevision { get; set; }
///
/// SHA of the commit that was last successfully synced from Git.
///
public string? GitLastSyncedCommit { get; set; }
///
/// When the last successful Git sync completed.
///
public DateTime? GitLastSyncedAt { get; set; }
///
/// When true the background GitSyncService will poll this deployment
/// and sync whenever a new commit is detected.
///
public bool GitAutoSync { get; set; } = true;
///
/// For GitAppOfApps child deployments: the parent deployment that manages
/// this deployment's lifecycle. Null for top-level deployments.
///
public Guid? ParentDeploymentId { get; set; }
// Navigation
public App App { get; set; } = null!;
public Environment Environment { get; set; } = null!;
public KubernetesCluster Cluster { get; set; } = null!;
public GitRepository? GitRepository { get; set; }
public AppDeployment? ParentDeployment { get; set; }
public ICollection ChildDeployments { get; set; } = [];
public ICollection Manifests { get; set; } = [];
public ICollection Resources { get; set; } = [];
public ICollection StorageBindings { get; set; } = [];
public ICollection DatabaseBindings { get; set; } = [];
public ICollection CacheBindings { get; set; } = [];
public ICollection Routes { get; set; } = [];
}