{
  "openapi": "3.0.4",
  "info": {
    "title": "Parra Agent Gateway",
    "version": "v1"
  },
  "paths": {
    "/v1/venues": {
      "get": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Search venues by q/city, paged 20/page (venues:read). When date is given, each result is enriched with an availability summary for that date and partySize.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "city",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "date",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "partySize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/venues/{code}/menu": {
      "get": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Public menu (categories, items, prices) for a venue (venues:read). Optional menuId selects one of the venue's menus; defaults to the first.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "menuId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/venues/{code}": {
      "get": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Venue card + policy text + menu URL + bookingMode for a client code (venues:read). 404 for an unknown code; 403 when the key has no grant for that venue.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/venues/{code}/availability": {
      "get": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Availability slots for a venue on a date/partySize (availability:read). Passthrough to the Reservations service.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "date",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "partySize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/reservations": {
      "post": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Create a no-deposit reservation for a diner (reservations:write). Returns bookingMode: AGENT_OK (booked), HANDOFF_DEPOSIT (handoffUrl), or CLOSED. idempotencyKey is required and replayed for 24h.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateReservationInput"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/reservations/{code}": {
      "get": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Get a reservation created by this key (reservations:read), or any reservation with a manageToken.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "manageToken",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/reservations/{code}/cancel": {
      "post": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Cancel a reservation created by this key (reservations:write), or any reservation with a manageToken.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "manageToken",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/admin/keys": {
      "post": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Issue a partner + API key (internal, X-Internal-Secret). Returns the plaintext key exactly once.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateKeyRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "get": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "List all keys with their derived state (ACTIVE/THROTTLED/SUSPENDED), current limits and abuse notices (internal).",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/admin/keys/{keyId}/suspend": {
      "post": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Suspend a key (internal). Subsequent requests with it fail authentication.",
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/admin/keys/{keyId}/reactivate": {
      "post": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Reactivate a suspended key (internal).",
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/admin/keys/{keyId}/tier": {
      "put": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Change a key's pricing tier (internal). Tier lives on the owning partner.",
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateTierRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/jobs/aggregate-usage": {
      "post": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Aggregate AgentCalls into AgentUsageLedger per key/period/tool (cost units from AgentPricingTiers, confirmed bookings via the Reservations service). Idempotent. Body: { period?: yyyy-MM }.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AggregateUsageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/jobs/abuse-check": {
      "post": {
        "tags": [
          "Parra.AgentGateway"
        ],
        "description": "Nightly abuse check (A1 §4.8): over the last 24h, throttle keys whose availability/booking ratio or sustained call rate is abusive; a second strike within 7 days suspends the key. Records an AgentPartners notice and emails the partner contact when an email service is configured.",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AgentContext": {
        "type": "object",
        "properties": {
          "agentName": {
            "type": "string",
            "nullable": true
          },
          "conversationRef": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "AggregateUsageRequest": {
        "type": "object",
        "properties": {
          "period": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "CreateKeyRequest": {
        "type": "object",
        "properties": {
          "partnerName": {
            "type": "string",
            "nullable": true
          },
          "partnerType": {
            "type": "string",
            "nullable": true
          },
          "tier": {
            "type": "string",
            "nullable": true
          },
          "contactEmail": {
            "type": "string",
            "nullable": true
          },
          "scopes": {
            "type": "string",
            "nullable": true
          },
          "tenants": {
            "type": "string",
            "nullable": true
          },
          "rateLimitPerMin": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "dailyBookingLimit": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "isTest": {
            "type": "boolean"
          }
        },
        "additionalProperties": false
      },
      "CreateReservationInput": {
        "type": "object",
        "properties": {
          "venueCode": {
            "type": "string",
            "nullable": true
          },
          "date": {
            "type": "string",
            "nullable": true
          },
          "time": {
            "type": "string",
            "nullable": true
          },
          "partySize": {
            "type": "integer",
            "format": "int32"
          },
          "guestName": {
            "type": "string",
            "nullable": true
          },
          "guestPhone": {
            "type": "string",
            "nullable": true
          },
          "guestEmail": {
            "type": "string",
            "nullable": true
          },
          "specialRequests": {
            "type": "string",
            "nullable": true
          },
          "agentContext": {
            "$ref": "#/components/schemas/AgentContext"
          },
          "idempotencyKey": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "UpdateTierRequest": {
        "type": "object",
        "properties": {
          "tier": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "description": "Agent API key. Enter: Bearer pk_live_… / pk_test_…",
        "scheme": "bearer"
      }
    }
  },
  "security": [
    {
      "ApiKey": [ ]
    }
  ],
  "tags": [
    {
      "name": "Parra.AgentGateway"
    }
  ]
}