{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/bewary/json-schema/bewary-billing-settings-schema.json",
  "title": "BillingSettings",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/bewary-billing-api-openapi.yml#/components/schemas/BillingSettings",
  "properties": {
    "auto_topup": {
      "$ref": "#/$defs/AutoTopup"
    },
    "low_balance_email": {
      "$ref": "#/$defs/LowBalanceEmail"
    },
    "card": {
      "anyOf": [
        {
          "$ref": "#/$defs/CardInfo"
        },
        {
          "type": "null"
        }
      ],
      "description": "The saved card for auto top-up, or null."
    },
    "last_top_up": {
      "anyOf": [
        {
          "$ref": "#/$defs/LastTopUp"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "type": "object",
  "required": [
    "auto_topup",
    "low_balance_email"
  ],
  "$defs": {
    "AutoTopup": {
      "properties": {
        "enabled": {
          "type": "boolean",
          "title": "Enabled",
          "description": "Off by default. Needs a saved card (POST /v1/billing/card).",
          "default": false
        },
        "pack": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "pack_20",
                "pack_100",
                "pack_500",
                "pack_2000"
              ]
            },
            {
              "type": "null"
            }
          ],
          "title": "Pack",
          "description": "The pack bought each time."
        },
        "threshold": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0.0
            },
            {
              "type": "null"
            }
          ],
          "title": "Threshold",
          "description": "Buy when a call takes the balance under this many credits. Below the pack's credits."
        }
      },
      "type": "object",
      "title": "AutoTopup"
    },
    "CardInfo": {
      "properties": {
        "brand": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Brand"
        },
        "last4": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Last4"
        }
      },
      "type": "object",
      "title": "CardInfo"
    },
    "LastTopUp": {
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "pending",
            "processing",
            "succeeded",
            "failed"
          ],
          "title": "Status"
        },
        "pack": {
          "type": "string",
          "title": "Pack"
        },
        "error": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Error",
          "description": "Stripe's decline code when it failed, e.g. card_declined."
        },
        "created_at": {
          "type": "string",
          "title": "Created At"
        },
        "finished_at": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Finished At"
        }
      },
      "type": "object",
      "required": [
        "status",
        "pack",
        "created_at"
      ],
      "title": "LastTopUp"
    },
    "LowBalanceEmail": {
      "properties": {
        "enabled": {
          "type": "boolean",
          "title": "Enabled",
          "description": "On by default; sent once each time the balance falls under the threshold after having been at or over it.",
          "default": true
        },
        "threshold": {
          "type": "integer",
          "minimum": 0.0,
          "title": "Threshold",
          "default": 2000
        }
      },
      "type": "object",
      "title": "LowBalanceEmail"
    }
  }
}