{
  "openapi": "3.1.0",
  "info": {
    "title": "UPCBay Barcode & Agent Commerce API",
    "version": "1.0.0",
    "description": "API for validating barcodes, calculating GS1 check digits, converting UPC to EAN, querying pricing, and programmatic purchasing with agent payment support (MPP / x402).",
    "contact": {
      "name": "UPCBay Support",
      "url": "https://upcbay.com/contact",
      "email": "support@upcbay.com"
    }
  },
  "servers": [
    {
      "url": "https://upcbay.com/api",
      "description": "Production server"
    }
  ],
  "paths": {
    "/v1/validate/{barcode}": {
      "get": {
        "summary": "Validate Barcode",
        "description": "Validates a 12-digit UPC or 13-digit EAN barcode and verifies its checksum.",
        "operationId": "validateBarcode",
        "parameters": [
          {
            "name": "barcode",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "12-digit UPC-A or 13-digit EAN-13 barcode"
          }
        ],
        "responses": {
          "200": {
            "description": "Validation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationResult"
                }
              }
            }
          }
        }
      }
    },
    "/v1/calculate-check-digit": {
      "post": {
        "summary": "Calculate Check Digit",
        "description": "Calculates the GS1 Modulo 10 check digit for an 11-digit UPC or 12-digit EAN prefix.",
        "operationId": "calculateCheckDigit",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prefix": {
                    "type": "string",
                    "example": "01234567890"
                  }
                },
                "required": ["prefix"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculated check digit result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "prefix": { "type": "string" },
                    "check_digit": { "type": "integer" },
                    "full_barcode": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/pricing": {
      "get": {
        "summary": "Get Barcode Package Pricing",
        "description": "Retrieves available UPC/EAN barcode packages and tier pricing.",
        "operationId": "getPricing",
        "responses": {
          "200": {
            "description": "List of packages and prices",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "packages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PackageTier"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/orders/purchase": {
      "post": {
        "summary": "Purchase Barcode Bundle",
        "description": "Initiates purchase of authentic UPC & EAN barcodes with agent-native payments.",
        "operationId": "purchaseBarcodes",
        "x-payment-info": {
          "intent": "charge",
          "methods": ["stripe", "lightning", "tempo", "card", "x402"],
          "currency": "USD",
          "tiers": [
            { "quantity": 1, "amount": 8.00 },
            { "quantity": 5, "amount": 20.00 },
            { "quantity": 10, "amount": 30.00 },
            { "quantity": 25, "amount": 55.00 },
            { "quantity": 50, "amount": 85.00 },
            { "quantity": 100, "amount": 130.00 },
            { "quantity": 500, "amount": 375.00 },
            { "quantity": 1000, "amount": 600.00 }
          ]
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "package_id": {
                    "type": "string",
                    "example": "10_upc_ean_bundles"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                },
                "required": ["package_id", "email"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Order created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "order_id": { "type": "string" },
                    "download_url": { "type": "string" },
                    "status": { "type": "string" }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment Required (x402 / MPP)",
            "headers": {
              "WWW-Authenticate": {
                "schema": { "type": "string" },
                "description": "Payment challenge for x402 / MPP protocols"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ValidationResult": {
        "type": "object",
        "properties": {
          "barcode": { "type": "string" },
          "valid": { "type": "boolean" },
          "format": { "type": "string", "enum": ["UPC-A", "EAN-13", "Invalid"] },
          "check_digit_valid": { "type": "boolean" },
          "calculated_check_digit": { "type": "integer" }
        }
      },
      "PackageTier": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "quantity": { "type": "integer" },
          "price_usd": { "type": "number" },
          "unit_price_usd": { "type": "number" }
        }
      }
    }
  }
}
