{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/carbonmark-com/json-schema/carbonmark-com-billing-projection-schema.json",
  "title": "BillingProjection",
  "x-generated": "2026-11-18",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/carbonmark-com-openapi.json#/components/schemas/BillingProjection",
  "type": "object",
  "properties": {
    "billing_account": {
      "anyOf": [
        {
          "$ref": "#/$defs/BillingAccount"
        },
        {
          "type": "null"
        }
      ]
    },
    "setup_policy": {
      "type": "object",
      "properties": {
        "terms": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "version": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                }
              },
              "required": [
                "version",
                "url"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "acceptance_enabled": {
          "type": "boolean"
        }
      },
      "required": [
        "terms",
        "acceptance_enabled"
      ]
    },
    "funding_access": {
      "type": "object",
      "properties": {
        "allowed": {
          "type": "boolean"
        },
        "reason": {
          "type": "string"
        },
        "minimum_payment_usd": {
          "exclusiveMinimum": 0,
          "type": "number"
        }
      },
      "required": [
        "allowed",
        "reason",
        "minimum_payment_usd"
      ]
    },
    "funding_pricing": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "revision": {
              "pattern": "^[1-9][0-9]*$",
              "type": "string"
            },
            "processing_fee_bps": {
              "minimum": 0,
              "maximum": 10000,
              "type": "integer"
            },
            "currency": {
              "type": "string",
              "enum": [
                "USD"
              ]
            },
            "rounding": {
              "type": "string",
              "enum": [
                "half_up"
              ]
            }
          },
          "required": [
            "revision",
            "processing_fee_bps",
            "currency",
            "rounding"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "setup": {
      "type": "object",
      "properties": {
        "has_sandbox_key": {
          "type": "boolean"
        },
        "has_test_order": {
          "type": "boolean"
        },
        "business_details_complete": {
          "type": "boolean"
        },
        "terms_accepted": {
          "type": "boolean"
        },
        "next_action": {
          "type": "string"
        }
      },
      "required": [
        "has_sandbox_key",
        "has_test_order",
        "business_details_complete",
        "terms_accepted",
        "next_action"
      ]
    },
    "production_access": {
      "type": "object",
      "properties": {
        "eligible": {
          "type": "boolean"
        },
        "has_production_key": {
          "type": "boolean"
        },
        "reason": {
          "type": "string"
        }
      },
      "required": [
        "eligible",
        "has_production_key",
        "reason"
      ]
    },
    "business_details": {
      "anyOf": [
        {
          "$ref": "#/$defs/BillingProfile"
        },
        {
          "type": "null"
        }
      ]
    },
    "terms": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "version": {
              "type": "string"
            },
            "accepted_at": {
              "format": "date-time",
              "type": "string"
            }
          },
          "required": [
            "version",
            "accepted_at"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "balance": {
      "anyOf": [
        {
          "$ref": "#/$defs/PrepaidBalance"
        },
        {
          "type": "null"
        }
      ]
    },
    "plan": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "number"
            },
            "name": {
              "type": "string"
            },
            "limits": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "limit_type": {
                    "type": "string"
                  },
                  "amount_usd": {
                    "type": "number"
                  },
                  "duration_days": {
                    "anyOf": [
                      {
                        "type": "number"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "limit_type",
                  "amount_usd",
                  "duration_days"
                ]
              }
            }
          },
          "required": [
            "id",
            "name",
            "limits"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "allowances": {
      "anyOf": [
        {
          "$ref": "#/$defs/PrepaidAllowances"
        },
        {
          "type": "null"
        }
      ]
    },
    "recovery": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "account_next_available_at": {
              "anyOf": [
                {
                  "format": "date-time",
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "key_next_available_at": {
              "anyOf": [
                {
                  "format": "date-time",
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "requested_amount_available_at": {
              "anyOf": [
                {
                  "format": "date-time",
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "blocker": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "calculated_at": {
              "format": "date-time",
              "type": "string"
            }
          },
          "required": [
            "account_next_available_at",
            "key_next_available_at",
            "requested_amount_available_at",
            "blocker",
            "calculated_at"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "restrictions": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "code": {
                "anyOf": [
                  {
                    "type": "string",
                    "enum": [
                      "MANUAL_REVIEW"
                    ]
                  },
                  {
                    "type": "string",
                    "enum": [
                      "PAYMENT_REVIEW"
                    ]
                  },
                  {
                    "type": "string",
                    "enum": [
                      "COMPLIANCE_REVIEW"
                    ]
                  },
                  {
                    "type": "string",
                    "enum": [
                      "REFUND_RECONCILIATION"
                    ]
                  },
                  {
                    "type": "string",
                    "enum": [
                      "UNDER_REVIEW"
                    ]
                  }
                ]
              },
              "message": {
                "type": "string"
              },
              "action": {
                "type": "string",
                "enum": [
                  "contact_support"
                ]
              }
            },
            "required": [
              "code",
              "message",
              "action"
            ]
          }
        }
      ]
    },
    "messages": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "action": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "top_up"
                ]
              },
              {
                "type": "string",
                "enum": [
                  "contact_sales"
                ]
              },
              {
                "type": "string",
                "enum": [
                  "contact_support"
                ]
              },
              {
                "type": "string",
                "enum": [
                  "retry"
                ]
              }
            ]
          },
          "amount_owed": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "next_available_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "code",
          "message",
          "action",
          "amount_owed",
          "next_available_at"
        ]
      }
    }
  },
  "required": [
    "billing_account",
    "setup_policy",
    "funding_access",
    "funding_pricing",
    "setup",
    "production_access",
    "business_details",
    "terms",
    "balance",
    "plan",
    "allowances",
    "recovery",
    "restrictions",
    "messages"
  ],
  "$defs": {
    "BillingAccount": {
      "type": "object",
      "properties": {
        "team_id": {
          "type": "number"
        },
        "billing_mode": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "prepaid"
              ]
            },
            {
              "type": "string",
              "enum": [
                "postpaid"
              ]
            }
          ]
        },
        "plan_id": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "state": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "pending"
              ]
            },
            {
              "type": "string",
              "enum": [
                "active"
              ]
            },
            {
              "type": "string",
              "enum": [
                "suspended"
              ]
            }
          ]
        }
      },
      "required": [
        "team_id",
        "billing_mode",
        "plan_id",
        "state"
      ]
    },
    "BillingProfile": {
      "additionalProperties": false,
      "type": "object",
      "properties": {
        "company_name": {
          "minLength": 1,
          "type": "string"
        },
        "website": {
          "format": "uri",
          "type": "string"
        },
        "use_case": {
          "minLength": 1,
          "type": "string"
        },
        "legal_entity_name": {
          "minLength": 1,
          "type": "string"
        },
        "country": {
          "pattern": "^[A-Za-z]{2}$",
          "type": "string"
        },
        "business_use_confirmed": {
          "type": "boolean",
          "enum": [
            true
          ]
        },
        "sanctions_confirmed": {
          "type": "boolean",
          "enum": [
            true
          ]
        },
        "terms_version": {
          "minLength": 1,
          "type": "string"
        },
        "team_id": {
          "type": "number"
        },
        "details_revision": {
          "minimum": 0,
          "type": "integer"
        },
        "terms_accepted_at": {
          "format": "date-time",
          "type": "string"
        },
        "accepted_by": {
          "format": "uuid",
          "type": "string"
        },
        "compliance_status": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "pending"
              ]
            },
            {
              "type": "string",
              "enum": [
                "cleared"
              ]
            },
            {
              "type": "string",
              "enum": [
                "blocked"
              ]
            }
          ]
        }
      },
      "required": [
        "company_name",
        "website",
        "use_case",
        "legal_entity_name",
        "country",
        "business_use_confirmed",
        "sanctions_confirmed",
        "terms_version",
        "team_id",
        "details_revision",
        "terms_accepted_at",
        "accepted_by",
        "compliance_status"
      ]
    },
    "PrepaidAllowances": {
      "type": "object",
      "properties": {
        "maximum_balance": {
          "type": "number"
        },
        "balance_headroom": {
          "type": "number"
        },
        "minimum_top_up": {
          "exclusiveMinimum": 0,
          "type": "number"
        },
        "maximum_top_up": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "account_spend": {
          "type": "number"
        },
        "account_spend_limit": {
          "type": "number"
        },
        "account_spend_remaining": {
          "type": "number"
        },
        "key_ceiling": {
          "type": "number"
        },
        "key_limit": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "key_spend": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "key_spend_remaining": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "window_hours": {
          "minimum": 24,
          "maximum": 87600,
          "multipleOf": 24,
          "type": "integer"
        },
        "key_window_hours": {
          "type": "number",
          "enum": [
            168
          ]
        },
        "top_up_total_limit": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "top_up_total_used": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "top_up_total_remaining": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "top_up_window_hours": {
          "anyOf": [
            {
              "minimum": 24,
              "maximum": 87600,
              "multipleOf": 24,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ]
        },
        "calculated_at": {
          "format": "date-time",
          "type": "string"
        }
      },
      "required": [
        "maximum_balance",
        "balance_headroom",
        "minimum_top_up",
        "maximum_top_up",
        "account_spend",
        "account_spend_limit",
        "account_spend_remaining",
        "key_ceiling",
        "key_limit",
        "key_spend",
        "key_spend_remaining",
        "window_hours",
        "calculated_at"
      ]
    },
    "PrepaidBalance": {
      "type": "object",
      "properties": {
        "posted": {
          "type": "number"
        },
        "available": {
          "type": "number"
        },
        "reserved": {
          "type": "number"
        },
        "pending_top_ups": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "enum": [
            "USD"
          ]
        }
      },
      "required": [
        "posted",
        "available",
        "reserved",
        "pending_top_ups",
        "currency"
      ]
    }
  }
}