{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/robase-dev/json-schema/robase-dev-otpdetails-schema.json",
  "title": "OTPDetails",
  "x-generated": "2026-10-31",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/robase-dev-openapi.yaml#/components/schemas/OTPDetails",
  "type": "object",
  "required": [
    "id",
    "workspace_id",
    "phone_number",
    "country_code",
    "credit_cost",
    "status",
    "code_length",
    "ttl_seconds",
    "attempt_count",
    "max_attempts",
    "expired_at",
    "created_at"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "workspace_id": {
      "type": "string",
      "format": "uuid"
    },
    "phone_number": {
      "type": "string"
    },
    "country_code": {
      "type": "string",
      "description": "ISO 3166-1 alpha-2 country code"
    },
    "credit_cost": {
      "type": "integer"
    },
    "status": {
      "type": "string",
      "enum": [
        "pending",
        "sent",
        "verified",
        "expired",
        "failed"
      ],
      "description": "The OTP's state. There is no `delivered` value: a carrier receipt\nis reported through `delivered_at`, a `delivered` hop in\n`timeline`, and the `otp.delivered` webhook, while `status`\nstays where it was (normally `sent`).\n"
    },
    "code_length": {
      "type": "integer"
    },
    "ttl_seconds": {
      "type": "integer"
    },
    "attempt_count": {
      "type": "integer",
      "description": "Verification attempts made so far"
    },
    "max_attempts": {
      "type": "integer",
      "description": "Attempt budget before the OTP is burned"
    },
    "sent_at": {
      "type": "string",
      "format": "date-time"
    },
    "delivered_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the first delivery receipt arrived, from the carrier for the\nSMS leg or from WhatsApp for a WhatsApp leg. Absent until then, and\nabsent for good on routes that send no receipt. This, not\n`status`, is how a polled OTP shows delivery.\n"
    },
    "verified_at": {
      "type": "string",
      "format": "date-time"
    },
    "failed_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the OTP was marked failed. Absent otherwise."
    },
    "failure_reason": {
      "type": "string",
      "description": "Reason token behind a failed status. See TimelineItem."
    },
    "expired_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the code stops being verifiable"
    },
    "metadata": {
      "type": "object",
      "additionalProperties": true
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "channel": {
      "type": "string",
      "enum": [
        "sms",
        "whatsapp",
        "both"
      ],
      "description": "Channel(s) this OTP was sent on. Codes from before WhatsApp OTP read `sms`."
    },
    "whatsapp_status": {
      "type": "string",
      "enum": [
        "pending",
        "sent",
        "delivered",
        "failed"
      ],
      "description": "The WhatsApp leg's own state. Present only when `channel` is\n`whatsapp` or `both`. Unlike `status`, this field does take\n`delivered`.\n"
    },
    "timeline": {
      "type": "array",
      "description": "Hops the OTP took, oldest first.",
      "items": {
        "$ref": "#/$defs/TimelineItem"
      }
    }
  },
  "$defs": {
    "TimelineItem": {
      "type": "object",
      "required": [
        "at",
        "status"
      ],
      "properties": {
        "at": {
          "type": "string",
          "format": "date-time",
          "description": "When the hop happened (RFC 3339)."
        },
        "status": {
          "type": "string",
          "description": "`queued` (charged and waiting for the worker), then the message's\nown status values: `sent`, `delivered`, `failed`, `blocked`, and for\nOTPs `verified` and `expired`. A hop is listed only when its time\nis known; `status` on the parent object is always authoritative.\n"
        },
        "reason": {
          "type": "string",
          "description": "Stable machine token. Present on a terminal hop when known, and on\n`sent` when the anti-spam screen flagged but still sent the message.\nTokens: `send_failed`, `delivery_failed`, `antispam_blocked`,\n`antispam_flagged`, `max_attempts_exceeded`, `workspace_suspended`,\n`workspace_restricted`, `kyc_required`. Omitted when unknown.\n"
        },
        "refunded": {
          "type": "boolean",
          "description": "On a terminal `failed` or `blocked` hop only. Reflects the credit\nledger: `true` means the charge was returned.\n"
        }
      }
    }
  }
}