{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/payments-ai/json-schema/payments-ai-public-api-product-schema.json",
  "title": "PublicApiProduct",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/payments-ai-products-api-openapi.yml#/components/schemas/PublicApiProduct",
  "type": "object",
  "required": [
    "id",
    "merchantId",
    "name",
    "status",
    "revenue",
    "discountCodes",
    "plans",
    "createdAt",
    "updatedAt"
  ],
  "properties": {
    "id": {
      "type": "string"
    },
    "merchantId": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "description": {
      "type": [
        "string",
        "null"
      ]
    },
    "status": {
      "$ref": "#/$defs/ProductStatus"
    },
    "revenue": {
      "type": "number",
      "format": "decimal"
    },
    "discountCodes": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Deprecated: legacy discount codes on the product. New promos are first-class DiscountCode entities. Retained for backward compatibility until migration (PAIM-285)."
    },
    "plans": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/PublicApiPlanVariant"
      }
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "deletedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "imageUrl": {
      "type": [
        "string",
        "null"
      ],
      "description": "Presigned URL resolved on the read side from the stored S3 image key."
    },
    "activeSubscriptionCount": {
      "type": "integer",
      "format": "int32",
      "description": "Active subscriptions billed against this product"
    },
    "totalSalesCount": {
      "type": "integer",
      "format": "int32",
      "description": "Lifetime sales count for delete eligibility"
    },
    "canPermanentlyDelete": {
      "type": "boolean",
      "description": "True when draft with zero sales and zero active subscriptions"
    },
    "productTaxCodeId": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "$defs": {
    "BillingPeriod": {
      "type": "string",
      "enum": [
        "day",
        "week",
        "month",
        "year"
      ]
    },
    "PlanType": {
      "type": "string",
      "enum": [
        "free-access",
        "one-time",
        "recurring"
      ]
    },
    "ProductStatus": {
      "type": "string",
      "enum": [
        "active",
        "draft",
        "archived"
      ]
    },
    "PublicApiPlanVariant": {
      "type": "object",
      "required": [
        "id",
        "productId",
        "name",
        "type",
        "billingPeriod",
        "lengthOfBillingPeriod",
        "amount",
        "initialPrice",
        "currency",
        "createdAt",
        "updatedAt"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "productId": {
          "type": "string"
        },
        "name": {
          "type": "string",
          "maxLength": 30,
          "description": "Merchant-facing display name for the variant (e.g. Pro, Monthly)."
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 80
        },
        "type": {
          "$ref": "#/$defs/PlanType"
        },
        "billingPeriod": {
          "$ref": "#/$defs/BillingPeriod"
        },
        "lengthOfBillingPeriod": {
          "type": "integer",
          "format": "int32"
        },
        "amount": {
          "allOf": [
            {
              "$ref": "#/$defs/SharedTypes.MoneyAmountValue"
            }
          ],
          "description": "Strictly flat pricing amount"
        },
        "initialPrice": {
          "allOf": [
            {
              "$ref": "#/$defs/SharedTypes.MoneyAmountValue"
            }
          ],
          "description": "Amount charged at checkout today. Zero for recurring plans with a free trial; otherwise matches amount."
        },
        "currency": {
          "$ref": "#/$defs/SharedTypes.CurrencyCode"
        },
        "freeTrial": {
          "type": "integer",
          "format": "int32"
        },
        "taxBehavior": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "exclusive",
            "inclusive"
          ],
          "description": "Per-plan override when set; otherwise inherits merchant default."
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "SharedTypes.CurrencyCode": {
      "type": "string",
      "pattern": "^[a-z]{3}$",
      "description": "ISO 4217 currency code. Always lowercase (e.g. 'usd', 'eur')."
    },
    "SharedTypes.MoneyAmountValue": {
      "type": "number",
      "format": "decimal",
      "description": "Decimal money amount for financial values."
    }
  }
}