{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/eurobase-dev/json-schema/eurobase-dev-account-usage-response-schema.json",
  "title": "AccountUsageResponse",
  "x-generated": "2026-11-07",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/eurobase-dev-openapi.json#/components/schemas/AccountUsageResponse",
  "type": "object",
  "required": [
    "plan",
    "scope",
    "period",
    "lastUpdatedAt",
    "status",
    "meters",
    "runtimeUsage",
    "estimatedCost",
    "billingState",
    "billingSubscription",
    "actionQuotas",
    "resourceContributors",
    "projection"
  ],
  "properties": {
    "plan": {
      "type": "object",
      "required": [
        "code",
        "name",
        "pricingVersion"
      ],
      "properties": {
        "code": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "pricingVersion": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "scope": {
      "type": "object",
      "required": [
        "kind",
        "organizationId",
        "userId"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "user",
            "organization"
          ]
        },
        "organizationId": {
          "type": [
            "string",
            "null"
          ]
        },
        "userId": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "period": {
      "$ref": "#/$defs/UsageWindow"
    },
    "lastUpdatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "status": {
      "type": "string",
      "enum": [
        "available",
        "empty",
        "unavailable"
      ]
    },
    "meters": {
      "type": "array",
      "items": {
        "allOf": [
          {
            "$ref": "#/$defs/UsageMeterRow"
          },
          {
            "type": "object",
            "required": [
              "used",
              "limit",
              "resetAt",
              "state",
              "recoveryActions"
            ],
            "properties": {
              "used": {
                "type": "string",
                "pattern": "^[0-9]+(?:\\.[0-9]+)?$"
              },
              "reserved": {
                "type": "string",
                "description": "Build seconds held for builds in progress, separate from consumed usage."
              },
              "limit": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "resetAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "state": {
                "type": "string",
                "enum": [
                  "ok",
                  "blocked",
                  "unavailable"
                ]
              },
              "recoveryActions": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        ]
      }
    },
    "runtimeUsage": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "label",
            "usedSmallEquivalentHours",
            "includedSmallEquivalentHours",
            "remainingSmallEquivalentHours",
            "state",
            "sourceMeters",
            "resetStrategy"
          ],
          "properties": {
            "label": {
              "type": "string"
            },
            "usedSmallEquivalentHours": {
              "type": "string"
            },
            "includedSmallEquivalentHours": {
              "type": "string"
            },
            "remainingSmallEquivalentHours": {
              "type": "string"
            },
            "state": {
              "type": "string",
              "enum": [
                "ok",
                "blocked"
              ]
            },
            "sourceMeters": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "resetStrategy": {
              "type": "string"
            }
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "estimatedCost": {
      "anyOf": [
        {
          "$ref": "#/$defs/EstimatedCost"
        },
        {
          "type": "null"
        }
      ]
    },
    "billingState": {
      "$ref": "#/$defs/BillingUsageState"
    },
    "billingSubscription": {
      "$ref": "#/$defs/BillingSubscriptionState"
    },
    "actionQuotas": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/AccountActionQuota"
      }
    },
    "resourceContributors": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AccountUsageResourceContributor"
      }
    },
    "projection": {
      "type": "object",
      "required": [
        "status",
        "asOf",
        "pendingCount",
        "pendingCountIsLowerBound",
        "quarantinedCount",
        "quarantinedCountIsLowerBound",
        "oldestPendingAt",
        "lagMs"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "ready",
            "applying",
            "delayed",
            "rebuilding",
            "blocked",
            "unavailable"
          ]
        },
        "asOf": {
          "type": "string",
          "format": "date-time"
        },
        "pendingCount": {
          "type": "integer",
          "minimum": 0
        },
        "pendingCountIsLowerBound": {
          "type": "boolean"
        },
        "quarantinedCountIsLowerBound": {
          "type": "boolean"
        },
        "quarantinedCount": {
          "type": "integer",
          "minimum": 0
        },
        "oldestPendingAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "lagMs": {
          "type": "integer",
          "minimum": 0
        }
      }
    }
  },
  "$defs": {
    "AccountActionQuota": {
      "type": "object",
      "description": "Current API-owned abuse/action allowance. This is separate from monthly usage meters.",
      "additionalProperties": false,
      "required": [
        "actionCode",
        "metricCode",
        "label",
        "used",
        "limit",
        "resetAt",
        "state",
        "plan",
        "recoveryActions"
      ],
      "properties": {
        "actionCode": {
          "type": "string",
          "enum": [
            "deploy"
          ]
        },
        "metricCode": {
          "type": "string",
          "enum": [
            "deployments"
          ]
        },
        "label": {
          "type": "string"
        },
        "used": {
          "type": "string",
          "pattern": "^[0-9]+(?:\\.[0-9]+)?$"
        },
        "limit": {
          "type": "string",
          "pattern": "^[0-9]+(?:\\.[0-9]+)?$"
        },
        "resetAt": {
          "type": "string",
          "format": "date-time"
        },
        "state": {
          "type": "string",
          "enum": [
            "available",
            "blocked"
          ]
        },
        "plan": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "code",
            "name",
            "pricingVersion"
          ],
          "properties": {
            "code": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "pricingVersion": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        },
        "recoveryActions": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": [
              "open_usage",
              "wait_until_reset",
              "request_plan_change"
            ]
          }
        }
      }
    },
    "AccountUsageResourceContributor": {
      "type": "object",
      "required": [
        "projectId",
        "projectName",
        "resourceType",
        "resourceLabel",
        "meter",
        "estimatedCost",
        "share",
        "updatedAt"
      ],
      "properties": {
        "projectId": {
          "type": "string"
        },
        "projectName": {
          "type": "string"
        },
        "resourceType": {
          "type": "string"
        },
        "resourceLabel": {
          "type": "string"
        },
        "meter": {
          "anyOf": [
            {
              "$ref": "#/$defs/UsageMeterRow"
            },
            {
              "type": "null"
            }
          ]
        },
        "estimatedCost": {
          "anyOf": [
            {
              "$ref": "#/$defs/EstimatedCost"
            },
            {
              "type": "null"
            }
          ]
        },
        "share": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 1
        },
        "updatedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    },
    "BillingSubscriptionState": {
      "type": "object",
      "required": [
        "state",
        "label",
        "planCode",
        "currentPeriodEnd",
        "cancelAtPeriodEnd",
        "manageBillingAvailable"
      ],
      "properties": {
        "state": {
          "type": "string",
          "enum": [
            "free",
            "granted",
            "processing",
            "active",
            "canceling",
            "past_due",
            "unpaid",
            "canceled"
          ]
        },
        "label": {
          "type": "string"
        },
        "planCode": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "free",
            "starter",
            "pro",
            null
          ]
        },
        "currentPeriodEnd": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "cancelAtPeriodEnd": {
          "type": "boolean"
        },
        "manageBillingAvailable": {
          "type": "boolean"
        }
      }
    },
    "BillingUsageState": {
      "type": "object",
      "required": [
        "state",
        "label",
        "meterAvailability",
        "billingMonth"
      ],
      "properties": {
        "state": {
          "type": "string",
          "enum": [
            "Estimated",
            "Finalizing",
            "Final"
          ]
        },
        "label": {
          "type": "string"
        },
        "meterAvailability": {
          "type": "string",
          "enum": [
            "available",
            "unavailable"
          ]
        },
        "billingMonth": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "EstimatedCost": {
      "type": "object",
      "required": [
        "currency",
        "amount",
        "label",
        "pricingVersion"
      ],
      "properties": {
        "currency": {
          "type": "string",
          "enum": [
            "EUR"
          ]
        },
        "amount": {
          "type": "string",
          "pattern": "^[0-9]+\\.[0-9]{2}$"
        },
        "label": {
          "type": "string"
        },
        "pricingVersion": {
          "type": "string"
        }
      }
    },
    "UsageMeterRow": {
      "type": "object",
      "description": "Usage meter value returned by the API. Derived account meters such as runtime_average_latency_ms are computed by the API from DB-owned counters and are not accepted as persisted usage metrics.",
      "required": [
        "code",
        "label",
        "unit",
        "value"
      ],
      "properties": {
        "code": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "unit": {
          "type": "string"
        },
        "value": {
          "type": "string",
          "pattern": "^[0-9]+(?:\\.[0-9]+)?$"
        }
      }
    },
    "UsageWindow": {
      "type": "object",
      "required": [
        "code",
        "start",
        "end"
      ],
      "properties": {
        "code": {
          "type": "string",
          "enum": [
            "current_month",
            "billing_month"
          ]
        },
        "start": {
          "type": "string",
          "format": "date-time"
        },
        "end": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}