{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/codai-ro/json-schema/codai-ro-environment-schema.json",
  "title": "Environment",
  "description": "The stored environment row (camelCase, as persisted) plus snake_case `for_user_id` and, when known, the project's `isolation`. `metadata` never contains the enrolment token hash.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/codai-ro-projects-environments-api-openapi.yml#/components/schemas/Environment",
  "type": "object",
  "required": [
    "id",
    "projectId",
    "ownerUserId",
    "orgId",
    "forUserId",
    "for_user_id",
    "name",
    "slug",
    "provider",
    "region",
    "size",
    "state",
    "stateReason",
    "deviceId",
    "providerRef",
    "publicIp",
    "idleTimeoutMinutes",
    "lastActivityAt",
    "startedAt",
    "stoppedAt",
    "hourlyRateMicroEur",
    "includedHoursUsedSeconds",
    "metadata",
    "createdAt",
    "updatedAt"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "projectId": {
      "type": "string",
      "format": "uuid"
    },
    "ownerUserId": {
      "type": "string",
      "format": "uuid"
    },
    "orgId": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid"
    },
    "forUserId": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "In `vm_per_dev` projects, the developer this machine is pinned to."
    },
    "for_user_id": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "Same as `forUserId` (snake_case convenience)."
    },
    "isolation": {
      "$ref": "#/$defs/ProjectIsolation"
    },
    "name": {
      "type": "string"
    },
    "slug": {
      "type": "string",
      "description": "Globally unique preview hostname label (`https://<port>-<slug>.preview.codai.ro`)."
    },
    "provider": {
      "$ref": "#/$defs/EnvironmentProvider"
    },
    "region": {
      "type": [
        "string",
        "null"
      ]
    },
    "size": {
      "type": [
        "string",
        "null"
      ]
    },
    "state": {
      "$ref": "#/$defs/EnvironmentState"
    },
    "stateReason": {
      "type": [
        "string",
        "null"
      ]
    },
    "deviceId": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "The daemon's device row once enrolled."
    },
    "providerRef": {
      "type": [
        "string",
        "null"
      ],
      "description": "Provider-side id (server id, container id)."
    },
    "publicIp": {
      "type": [
        "string",
        "null"
      ]
    },
    "idleTimeoutMinutes": {
      "type": "integer",
      "minimum": 5,
      "maximum": 1440,
      "default": 30
    },
    "lastActivityAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "startedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "stoppedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "hourlyRateMicroEur": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Managed providers only; micro-EUR per hour."
    },
    "includedHoursUsedSeconds": {
      "type": "integer"
    },
    "metadata": {
      "type": "object",
      "additionalProperties": true,
      "description": "Provider/daemon facts, e.g. `daemon: { version, os, arch, enrolled_at }`, `budget_micro_eur`."
    },
    "prebuild": {
      "type": "boolean",
      "default": false,
      "description": "True for an unclaimed prebuild pool machine (owned by the project owner); cleared when claimed."
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time"
    }
  },
  "$defs": {
    "EnvironmentProvider": {
      "type": "string",
      "enum": [
        "byo",
        "openstack",
        "hetzner",
        "local",
        "gce"
      ],
      "description": "`byo` (bring your own machine; the daemon enrols with a token) is open to every key. `openstack` / `hetzner` are managed by the worker and billed hourly; `gce` (Google Cloud) offers on-demand CPU sizes `small`/`medium`/`large` (e2-standard-2/4/8) and the GPU size `gpu-l4` (Spot, 30-minute cap); it is available only where the deployment enables it AND to `super_admin` accounts (403 for everyone else); `local` is a developer convenience. Managed providers answer 403 until enabled for your key."
    },
    "EnvironmentState": {
      "type": "string",
      "enum": [
        "pending",
        "creating",
        "enrolling",
        "starting",
        "running",
        "stopping",
        "stopped",
        "archiving",
        "archived",
        "destroying",
        "destroyed",
        "error"
      ],
      "description": "Lifecycle state. `byo` starts in `pending` and reaches `enrolling` when the daemon enrols; managed providers start in `creating` and reach `running` once enrolled. `destroyed` is terminal."
    },
    "ProjectIsolation": {
      "type": "string",
      "enum": [
        "shared_vm",
        "container",
        "vm_per_dev"
      ],
      "description": "How a project's environments are shared. `shared_vm` (default) — one machine, many members; `container` — one container per member; `vm_per_dev` — one machine per developer, pinned via `for_user_id`."
    }
  }
}