# Services Contracts
#
# Type definitions for platform service registry.

{
  ServiceType = [| 'platform, 'infrastructure, 'utility |],
  ServiceCategory = [| 'orchestration, 'auth, 'dns, 'git, 'registry, 'api, 'ui, 'monitoring |],
  DeploymentMode = [| 'binary, 'docker, 'docker_compose, 'kubernetes, 'remote |],
  RestartPolicy = [| 'no, 'always, 'on_failure, 'unless_stopped |],
  HealthCheckType = [| 'http, 'tcp, 'command, 'file, 'none |],
  HttpMethod = [| 'GET, 'POST, 'HEAD |],
  ServiceStatus = [| 'running, 'stopped, 'failed, 'starting, 'stopping, 'unknown |],
  HealthStatus = [| 'healthy, 'unhealthy, 'unknown |],
  ServiceOperationType = [| 'start, 'stop, 'restart, 'reload, 'health_check |],

  ServiceRegistry = {
    services,
  },

  ServiceDefinition = {
    name | String,
    type | ServiceType,
    category | ServiceCategory,
    description | optional | String,
    required_for,
    dependencies,
    conflicts,
    deployment,
    health_check,
    startup,
    resources | optional,
  },

  ServiceDeployment = {
    mode | DeploymentMode,
    binary | optional,
    docker | optional,
    docker_compose | optional,
    kubernetes | optional,
    remote | optional,
  },

  BinaryDeployment = {
    binary_path | String,
    args,
    working_dir | optional | String,
    env,
    user | optional | String,
    group | optional | String,
  },

  DockerDeployment = {
    image | String,
    container_name | String,
    ports,
    volumes,
    environment,
    command | optional,
    networks,
    restart_policy | RestartPolicy,
  },

  DockerComposeDeployment = {
    compose_file | String,
    service_name | String,
    project_name | optional | String,
    env_file | optional | String,
  },

  KubernetesDeployment = {
    namespace | String,
    deployment_name | String,
    kubeconfig | optional | String,
    manifests_path | optional | String,
    helm_chart | optional,
  },

  HelmChart = {
    chart | String,
    release_name | String,
    repo_url | optional | String,
    version | optional | String,
    values_file | optional | String,
  },

  RemoteDeployment = {
    endpoint | String,
    tls_enabled | Bool,
    auth_token_path | optional | String,
    cert_path | optional | String,
  },

  HealthCheck = {
    type | HealthCheckType,
    http | optional,
    tcp | optional,
    command | optional,
    file | optional,
    interval | Number,
    retries | Number,
    timeout | Number,
  },

  HttpHealthCheck = {
    endpoint | String,
    expected_status | Number,
    method | HttpMethod,
    headers,
  },

  TcpHealthCheck = {
    host | String,
    port | Number,
  },

  CommandHealthCheck = {
    command | String,
    expected_exit_code | Number,
  },

  FileHealthCheck = {
    path | String,
    must_exist | Bool,
  },

  StartupConfig = {
    auto_start | Bool,
    start_timeout | Number,
    start_order | Number,
    restart_on_failure | Bool,
    max_restarts | Number,
  },

  ResourceLimits = {
    cpu_limit | optional | String,
    memory_limit | optional | String,
    disk_limit | optional | String,
  },

  ServiceState = {
    name | String,
    status | ServiceStatus,
    pid | optional | Number,
    started_at | optional | String,
    uptime | optional | Number,
    health_status | HealthStatus,
    last_health_check | optional | String,
    restart_count | Number,
  },

  ServiceOperation = {
    service_name | String,
    operation | ServiceOperationType,
    force | Bool,
    timeout | optional | Number,
  },
}
