{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/agentpmt-com/json-schema/agentpmt-com-customer-credit-history-response-schema.json",
  "title": "CustomerCreditHistoryResponse",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/agentpmt-com-credits-api-openapi.yml#/components/schemas/CustomerCreditHistoryResponse",
  "properties": {
    "success": {
      "type": "boolean",
      "title": "Success",
      "description": "`true` when the history lookup succeeded.",
      "default": true
    },
    "message": {
      "type": "string",
      "title": "Message",
      "description": "Human-readable status message.",
      "default": "Credit history retrieved successfully"
    },
    "data": {
      "$ref": "#/$defs/CustomerCreditHistoryData"
    }
  },
  "type": "object",
  "required": [
    "data"
  ],
  "$defs": {
    "CustomerCreditGrant": {
      "properties": {
        "_id": {
          "type": "string",
          "title": "Id",
          "description": "Grant document ID (serialized as `_id` in the response)."
        },
        "user_id": {
          "type": "string",
          "title": "User Id",
          "description": "Owning user ID."
        },
        "amount_credits": {
          "type": "integer",
          "title": "Amount Credits",
          "description": "Credits originally granted (positive integer)."
        },
        "amount_usd": {
          "type": "number",
          "title": "Amount Usd",
          "description": "USD equivalent of the grant at issuance."
        },
        "remaining_credits": {
          "type": "integer",
          "title": "Remaining Credits",
          "description": "Credits still available from this grant."
        },
        "credit_type": {
          "type": "string",
          "title": "Credit Type",
          "description": "Grant source classification (for example `admin_grant`, `referral_signup`, `x402_purchase`)."
        },
        "source_metadata": {
          "additionalProperties": true,
          "type": "object",
          "title": "Source Metadata",
          "description": "Free-form metadata supplied when the grant was created."
        },
        "date_created": {
          "type": "string",
          "title": "Date Created",
          "description": "ISO-8601 timestamp the grant was issued."
        },
        "pooled_at": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Pooled At",
          "description": "ISO-8601 timestamp the grant was added to the pool."
        },
        "expires_at": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Expires At",
          "description": "ISO-8601 timestamp the grant expires."
        }
      },
      "additionalProperties": true,
      "type": "object",
      "required": [
        "_id",
        "user_id",
        "amount_credits",
        "amount_usd",
        "remaining_credits",
        "credit_type",
        "date_created"
      ],
      "title": "CustomerCreditGrant"
    },
    "CustomerCreditHistoryData": {
      "properties": {
        "grants": {
          "items": {
            "$ref": "#/$defs/CustomerCreditGrant"
          },
          "type": "array",
          "title": "Grants",
          "description": "Credit grants owned by the caller, newest first."
        },
        "transactions": {
          "items": {
            "$ref": "#/$defs/CustomerCreditTransaction"
          },
          "type": "array",
          "title": "Transactions",
          "description": "Transaction audit trail, newest first."
        }
      },
      "type": "object",
      "required": [
        "grants",
        "transactions"
      ],
      "title": "CustomerCreditHistoryData"
    },
    "CustomerCreditTransaction": {
      "properties": {
        "_id": {
          "type": "string",
          "title": "Id",
          "description": "Transaction document ID (serialized as `_id` in the response)."
        },
        "user_id": {
          "type": "string",
          "title": "User Id",
          "description": "Owning user ID."
        },
        "transaction_type": {
          "type": "string",
          "title": "Transaction Type",
          "description": "One of `grant`, `expiration`, `revocation`, or `purchase` (tool deduction)."
        },
        "amount_credits": {
          "type": "integer",
          "title": "Amount Credits",
          "description": "Credits applied by this transaction. Negative for debits (expiration/revocation/purchase), positive for grants."
        },
        "amount_usd": {
          "type": "number",
          "title": "Amount Usd",
          "description": "USD equivalent of the transaction."
        },
        "balance_after_credits": {
          "type": "integer",
          "title": "Balance After Credits",
          "description": "Balance in credits after applying the transaction."
        },
        "balance_after_usd": {
          "type": "number",
          "title": "Balance After Usd",
          "description": "Balance in USD after applying the transaction."
        },
        "date_created": {
          "type": "string",
          "title": "Date Created",
          "description": "ISO-8601 timestamp of the transaction."
        }
      },
      "additionalProperties": true,
      "type": "object",
      "required": [
        "_id",
        "user_id",
        "transaction_type",
        "amount_credits",
        "amount_usd",
        "balance_after_credits",
        "balance_after_usd",
        "date_created"
      ],
      "title": "CustomerCreditTransaction"
    }
  }
}