{
  "openapi": "3.1.0",
  "info": {
    "title": "PlayaPotrero.cr Local Intelligence API",
    "version": "1.0.0",
    "description": "Read-only, provenance-backed local discovery tools for Playa Potrero and Costa Rica's Gold Coast. Results include temporal claims, confidence, verification state, and citation URLs."
  },
  "servers": [
    {
      "url": "https://5ctpklg4z4.execute-api.us-east-1.amazonaws.com"
    }
  ],
  "paths": {
    "/public/knowledge/search": {
      "get": {
        "operationId": "searchLocal",
        "summary": "Search verified local knowledge",
        "description": "Returns payment-neutral ranked entities and current temporal claims. This operation does not return private contact, moderation, identity, or behavioral data.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": { "type": "string", "minLength": 2, "maxLength": 500 }
          },
          {
            "name": "area",
            "in": "query",
            "schema": { "type": "string", "default": "playa-potrero", "maxLength": 120 }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "minimum": 1, "maximum": 12, "default": 8 }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked local entities with claims and citations",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/SearchResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/public/knowledge/entities/{entityId}": {
      "get": {
        "operationId": "getEntity",
        "summary": "Get one local entity and its temporal claims",
        "parameters": [
          {
            "name": "entityId",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "maxLength": 160 },
            "description": "Business entity identifier, with or without the business: prefix."
          }
        ],
        "responses": {
          "200": {
            "description": "Entity and claims",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["success", "entity"],
                  "properties": {
                    "success": { "const": true },
                    "entity": { "$ref": "#/components/schemas/Entity" }
                  }
                }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/agent/tools/search-local": {
      "post": {
        "operationId": "searchLocalTool",
        "summary": "Agent-friendly local search tool",
        "description": "Strict JSON tool equivalent of searchLocal. Mutating agent tools are intentionally not public.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": ["query"],
                "properties": {
                  "query": { "type": "string", "minLength": 2, "maxLength": 500 },
                  "areaSlug": { "type": "string", "maxLength": 120, "default": "playa-potrero" },
                  "limit": { "type": "integer", "minimum": 1, "maximum": 12, "default": 8 }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tool result",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/SearchResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Citation": {
        "type": "object",
        "required": ["source_id", "source_type", "title", "url", "confidence", "verification_state"],
        "properties": {
          "source_id": { "type": "string" },
          "source_type": { "type": "string" },
          "title": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "observed_at": { "type": ["string", "null"], "format": "date-time" },
          "expires_at": { "type": ["string", "null"], "format": "date-time" },
          "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
          "verification_state": { "enum": ["verified", "provisional", "candidate", "unverified"] }
        }
      },
      "Claim": {
        "type": "object",
        "required": ["id", "subject", "predicate", "confidence", "verification_state", "schema_version", "current"],
        "properties": {
          "id": { "type": "string" },
          "subject": { "type": "string" },
          "predicate": { "type": "string" },
          "value": {},
          "observed_at": { "type": ["string", "null"], "format": "date-time" },
          "valid_from": { "type": ["string", "null"], "format": "date-time" },
          "valid_to": { "type": ["string", "null"], "format": "date-time" },
          "expires_at": { "type": ["string", "null"], "format": "date-time" },
          "source_id": { "type": "string" },
          "evidence_id": { "type": "string" },
          "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
          "verification_state": { "type": "string" },
          "visibility": { "const": "public" },
          "schema_version": { "type": "string" },
          "current": { "type": "boolean" }
        }
      },
      "Entity": {
        "type": "object",
        "required": ["id", "entity_type", "name", "schema_version", "verification_state", "confidence", "citation", "claims"],
        "properties": {
          "id": { "type": "string" },
          "entity_type": { "type": "string" },
          "name": { "type": "string" },
          "slug": { "type": ["string", "null"] },
          "schema_version": { "type": "string" },
          "verification_state": { "type": "string" },
          "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
          "observed_at": { "type": ["string", "null"], "format": "date-time" },
          "citation": { "$ref": "#/components/schemas/Citation" },
          "claims": { "type": "array", "items": { "$ref": "#/components/schemas/Claim" } }
        }
      },
      "SearchResult": {
        "type": "object",
        "required": ["entity", "rank_position", "score", "score_factors"],
        "properties": {
          "entity": { "$ref": "#/components/schemas/Entity" },
          "rank_position": { "type": "integer", "minimum": 1 },
          "score": { "type": "number" },
          "score_factors": { "type": "array", "items": { "type": "object" } }
        }
      },
      "SearchResponse": {
        "type": "object",
        "required": ["success", "schema_version", "ranking_policy_version", "results"],
        "properties": {
          "success": { "const": true },
          "schema_version": { "type": "string" },
          "ranking_policy_version": { "type": "string" },
          "generated_at": { "type": "string", "format": "date-time" },
          "results": { "type": "array", "items": { "$ref": "#/components/schemas/SearchResult" } }
        }
      },
      "Error": {
        "type": "object",
        "required": ["success", "error"],
        "properties": {
          "success": { "const": false },
          "error": { "type": "string" },
          "request_id": { "type": "string" }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid request",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "NotFound": {
        "description": "Entity not found",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "RateLimited": {
        "description": "Request quota exceeded",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    }
  }
}
