{
  "openapi": "3.1.0",
  "info": {
    "title": "Growaify Autonomous Agent Commerce API",
    "version": "2.3.0",
    "description": "Agent-native commerce infrastructure. AI agents can discover services, request binding price quotes, submit orders, settle transactions (PayPal NCP primary; x402 USDC deferred), track fulfillment state machines, and receive webhook callbacks without human intervention."
  },
  "servers": [
    {
      "url": "https://growaify.com",
      "description": "Production Engine"
    }
  ],
  "paths": {
    "/api/v1/services": {
      "get": {
        "summary": "List services and constraints",
        "description": "Machine-readable service definitions with agent-specific discounts, capabilities, and explicit negative constraints.",
        "responses": {
          "200": {
            "description": "Service definitions"
          }
        }
      }
    },
    "/api/v1/quote": {
      "post": {
        "summary": "Generate binding price quote",
        "description": "Deterministic pricing with optional agent partner 20% commission attribution.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["service_id"],
                "properties": {
                  "service_id": {"type": "string"},
                  "is_agent": {"type": "boolean", "default": true},
                  "partner_id": {"type": "string"}
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Quote created"
          }
        }
      }
    },
    "/api/v1/orders": {
      "post": {
        "summary": "Create commercial order",
        "description": "Initiate state machine order with PayPal NCP and x402 USDC payment endpoints.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "service_id": {"type": "string"},
                  "quote_id": {"type": "string"},
                  "agent_id": {"type": "string"},
                  "email": {"type": "string"},
                  "webhook_url": {"type": "string"}
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Order initialized"
          }
        }
      }
    },
    "/api/v1/orders/{order_id}": {
      "get": {
        "summary": "Query order state and deliverables",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {"type": "string"}
          }
        ],
        "responses": {
          "200": {
            "description": "State machine progress and deliverable URLs"
          }
        }
      }
    },
    "/api/v1/orders/{order_id}/confirm_payment": {
      "post": {
        "summary": "Advance state machine post-payment",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {"type": "string"}
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "transaction_id": {"type": "string"}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Order marked paid and automated fulfillment triggered"
          }
        }
      }
    },
    "/api/v1/webhooks": {
      "post": {
        "summary": "Register event callback webhook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url"],
                "properties": {
                  "url": {"type": "string"},
                  "agent_id": {"type": "string"},
                  "events": {"type": "array", "items": {"type": "string"}}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook registered"
          }
        }
      }
    },
    "/api/v1/discover": {
      "get": {
        "summary": "Multi-parameter service discovery with SLA filtering",
        "parameters": [
          {"name": "capability", "in": "query", "schema": {"type": "string"}},
          {"name": "budget_max", "in": "query", "schema": {"type": "number"}},
          {"name": "billing", "in": "query", "schema": {"type": "string"}},
          {"name": "automation", "in": "query", "schema": {"type": "string"}},
          {"name": "language", "in": "query", "schema": {"type": "string"}},
          {"name": "region", "in": "query", "schema": {"type": "string"}},
          {"name": "payment_rail", "in": "query", "schema": {"type": "string"}},
          {"name": "max_fulfillment", "in": "query", "schema": {"type": "number"}}
        ],
        "responses": {
          "200": {"description": "Matching services"}
        }
      }
    },
    "/api/v1/capabilities/negotiate": {
      "post": {
        "summary": "Match required capabilities against service catalog",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["required_capabilities"],
                "properties": {
                  "required_capabilities": {"type": "array", "items": {"type": "string"}}
                }
              }
            }
          }
        },
        "responses": {
          "200": {"description": "Matching services sorted by coverage"}
        }
      }
    },
    "/api/v1/procure": {
      "post": {
        "summary": "Goal-based autonomous procurement engine",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "objective": {"type": "string"},
                  "budget": {"type": "number", "default": 100},
                  "currency": {"type": "string", "default": "USD"},
                  "requirements": {"type": "array", "items": {"type": "string"}},
                  "auto_purchase": {"type": "boolean", "default": true},
                  "agent_id": {"type": "string"},
                  "email": {"type": "string"}
                }
              }
            }
          }
        },
        "responses": {
          "201": {"description": "Procurement completed"},
          "402": {"description": "Payment failed"},
          "422": {"description": "No service matches requirements"}
        }
      }
    },
    "/api/v1/trust/status": {
      "get": {
        "summary": "Real-time verifiable performance and uptime telemetry",
        "responses": {
          "200": {"description": "Trust telemetry and declared SLA targets"}
        }
      }
    },
    "/api/v1/wallets/{agent_id}": {
      "get": {
        "summary": "Get or create agent wallet with balance",
        "parameters": [
          {"name": "agent_id", "in": "path", "required": true, "schema": {"type": "string"}}
        ],
        "responses": {
          "200": {"description": "Agent wallet with balance and transactions"}
        }
      }
    },
    "/api/v1/orders/{order_id}/verification": {
      "get": {
        "summary": "Cryptographic deliverable checksum and provenance",
        "parameters": [
          {"name": "order_id", "in": "path", "required": true, "schema": {"type": "string"}}
        ],
        "responses": {
          "200": {"description": "Verification status and deliverable checksums"}
        }
      }
    },
    "/api/v1/orders/{order_id}/review": {
      "post": {
        "summary": "Closed-loop acceptance or rejection handler",
        "parameters": [
          {"name": "order_id", "in": "path", "required": true, "schema": {"type": "string"}}
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["action"],
                "properties": {
                  "action": {"type": "string", "enum": ["accept", "reject"]},
                  "reason": {"type": "string"}
                }
              }
            }
          }
        },
        "responses": {
          "200": {"description": "Review recorded"}
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Health check endpoint",
        "responses": {
          "200": {"description": "Service health status"}
        }
      }
    },
    "/mcp": {
      "post": {
        "summary": "MCP (Model Context Protocol) JSON-RPC endpoint",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "jsonrpc": {"type": "string", "default": "2.0"},
                  "method": {"type": "string"},
                  "params": {"type": "object"},
                  "id": {}
                }
              }
            }
          }
        },
        "responses": {
          "200": {"description": "JSON-RPC response"}
        }
      }
    }
  }
}