{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/trustycap-com/json-schema/trustycap-com-billing-status-schema.json",
  "title": "BillingStatus",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/trustycap-com-openapi.yml#/components/schemas/BillingStatus",
  "type": "object",
  "properties": {
    "organization_id": {
      "type": "string",
      "pattern": "^org_[0-9A-HJKMNP-TV-Z]{26}$",
      "description": "Prefixed ULID (org_…)"
    },
    "status": {
      "type": "object",
      "properties": {
        "entitlement": {
          "type": "string",
          "enum": [
            "ACTIVE",
            "USER_BUDGET_LIMITED",
            "SUSPENDED_FOR_BILLING",
            "SUSPENDED_FOR_RISK",
            "RESTORING"
          ]
        },
        "collection": {
          "type": "string",
          "enum": [
            "CURRENT",
            "PAYMENT_PENDING",
            "RETRYING",
            "ACTION_REQUIRED",
            "PAST_DUE",
            "UNCOLLECTIBLE",
            "CURED"
          ]
        },
        "label": {
          "type": "string"
        },
        "tone": {
          "type": "string",
          "enum": [
            "ok",
            "info",
            "attention"
          ]
        },
        "collection_label": {
          "type": "string"
        },
        "production_allowed": {
          "type": "boolean"
        },
        "reason": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "since": {
          "oneOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "entitlement",
        "collection",
        "production_allowed"
      ],
      "additionalProperties": false
    },
    "remediation": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "action": {
              "type": "string",
              "enum": [
                "update_payment_method",
                "raise_spend_limit",
                "contact_billing"
              ]
            },
            "url": {
              "type": "string"
            },
            "detail": {
              "type": "string"
            }
          },
          "required": [
            "action",
            "url",
            "detail"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "period": {
      "type": "object",
      "properties": {
        "key": {
          "type": "string"
        },
        "starts_at": {
          "type": "string",
          "format": "date-time"
        },
        "ends_at": {
          "type": "string",
          "format": "date-time"
        },
        "next_close_at": {
          "type": "string",
          "format": "date-time"
        },
        "close_schedule_utc": {
          "type": "string"
        }
      },
      "required": [
        "key",
        "starts_at",
        "ends_at",
        "next_close_at"
      ],
      "additionalProperties": false
    },
    "spend": {
      "type": "object",
      "properties": {
        "current_period_cents": {
          "type": "integer"
        },
        "prior_period_cents": {
          "oneOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ]
        },
        "accrued_unbilled_cents": {
          "type": "integer",
          "description": "Rated this period and not yet invoiced."
        },
        "carried_forward_cents": {
          "type": "integer",
          "description": "A balance under $2 at an earlier month end, carried forward rather than waived: still owed, and collected with the next invoice."
        },
        "settled_this_period_cents": {
          "type": "integer",
          "description": "Invoiced by interim settlements this period; never billed again at close."
        },
        "paid_this_period_cents": {
          "type": "integer"
        },
        "projected_period_cents": {
          "oneOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ]
        },
        "storage_floor_cents": {
          "type": "integer",
          "description": "Cost committed by stored bytes held now, priced to the end of the period"
        },
        "currency": {
          "type": "string"
        }
      },
      "required": [
        "current_period_cents",
        "accrued_unbilled_cents",
        "carried_forward_cents",
        "settled_this_period_cents",
        "paid_this_period_cents",
        "currency"
      ],
      "additionalProperties": false
    },
    "exposure": {
      "type": "object",
      "properties": {
        "invoiced_unpaid_cents": {
          "type": "integer"
        },
        "settlement_threshold_cents": {
          "oneOf": [
            {
              "type": "integer",
              "description": "The unbilled balance (accrued plus carried forward) at which an interim invoice is made at once: $10, or a stricter amount a contract names."
            },
            {
              "type": "null"
            }
          ]
        },
        "remaining_before_settlement_cents": {
          "oneOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "controls": {
      "type": "object",
      "properties": {
        "hard_cap_cents": {
          "oneOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ]
        },
        "spend_alert_cents": {
          "type": "array",
          "items": {
            "type": "integer"
          }
        }
      },
      "additionalProperties": false
    },
    "payment_method": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "none",
            "valid",
            "expiring",
            "failed"
          ]
        },
        "brand": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "last4": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "expires": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "open_invoice": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "due_cents": {
              "type": "integer"
            },
            "hosted_url": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "next_attempt_at": {
              "oneOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            },
            "last_failure": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "billing_email": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "contacts": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          }
        },
        "additionalProperties": false
      }
    },
    "tax": {
      "type": "object",
      "properties": {
        "exempt": {
          "type": "string"
        },
        "tax_ids": {
          "type": "array",
          "items": {}
        },
        "address": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": true
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "terms": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "self_serve",
            "enterprise"
          ]
        },
        "net_days": {
          "oneOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "lines": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "meter": {
            "type": "string"
          },
          "display_name": {
            "type": "string"
          },
          "unit": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "billable_quantity": {
            "type": "number"
          },
          "net_cents": {
            "type": "integer"
          }
        },
        "additionalProperties": false
      }
    }
  },
  "required": [
    "organization_id",
    "status",
    "period",
    "spend",
    "payment_method",
    "lines"
  ],
  "additionalProperties": false
}