{
  "openapi": "3.1.0",
  "info": {
    "title": "WhatsDo Aesthetics & Wellness Database API",
    "version": "1.0.0",
    "description": "Verified selected Bay Area locations. Every published fact carries official-source evidence and an observation date. Unknown is different from false."
  },
  "servers": [
    {
      "url": "http://127.0.0.1:8787",
      "description": "Local development"
    },
    {
      "url": "{preview_url}",
      "description": "Preview deployment",
      "variables": {
        "preview_url": {
          "default": "https://preview.whatsdo.com"
        }
      }
    }
  ],
  "tags": [
    {
      "name": "locations"
    },
    {
      "name": "changes"
    },
    {
      "name": "analysis"
    },
    {
      "name": "corrections"
    }
  ],
  "components": {
    "schemas": {
      "Location": {
        "type": "object",
        "required": [
          "location_id",
          "business_id",
          "name",
          "business_types",
          "area",
          "address",
          "city",
          "official_url",
          "services",
          "booking",
          "evidence",
          "observed_at"
        ],
        "properties": {
          "location_id": {
            "type": "string"
          },
          "business_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "business_types": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "area": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "city": {
            "type": "string"
          },
          "official_url": {
            "type": "string",
            "format": "uri"
          },
          "services": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "booking": {
            "type": "object"
          },
          "evidence": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "field": {
                  "type": "string"
                },
                "value": {},
                "source_url": {
                  "type": "string",
                  "format": "uri"
                },
                "source_type": {
                  "type": "string"
                },
                "quote": {
                  "type": "string"
                },
                "observed_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "extraction_method": {
                  "type": "string"
                },
                "confidence": {
                  "type": "string"
                }
              }
            }
          },
          "observed_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Evidence": {
        "type": "object",
        "properties": {
          "field": {
            "type": "string"
          },
          "value": {},
          "source_url": {
            "type": "string",
            "format": "uri"
          },
          "source_type": {
            "type": "string"
          },
          "quote": {
            "type": "string"
          },
          "observed_at": {
            "type": "string",
            "format": "date-time"
          },
          "extraction_method": {
            "type": "string"
          },
          "confidence": {
            "type": "string"
          }
        }
      },
      "ChangeEvent": {
        "type": "object",
        "properties": {
          "change_id": {
            "type": "string"
          },
          "snapshot_from": {
            "type": [
              "string",
              "null"
            ]
          },
          "snapshot_to": {
            "type": "string"
          },
          "entity_type": {
            "type": "string"
          },
          "entity_id": {
            "type": "string"
          },
          "path": {
            "type": "string"
          },
          "operation": {
            "enum": [
              "add",
              "remove",
              "replace"
            ]
          },
          "before": {},
          "after": {},
          "detected_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AnalysisObservation": {
        "type": "object",
        "properties": {
          "analysis_id": {
            "type": "string"
          },
          "location_id": {
            "type": "string"
          },
          "source_platform": {
            "type": "string"
          },
          "source_kind": {
            "type": "string"
          },
          "source_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "observed_at": {
            "type": "string",
            "format": "date-time"
          },
          "analysis_method_version": {
            "type": "string"
          },
          "prompt_version": {
            "type": "string"
          },
          "sample_count": {
            "type": "integer"
          },
          "signals": {
            "type": "object"
          },
          "confidence": {
            "type": "string"
          },
          "raw_retained": {
            "const": false
          },
          "publishable": {
            "type": "boolean"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "locations"
        ],
        "summary": "Service health",
        "responses": {
          "200": {
            "description": "Healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/v1/locations": {
      "get": {
        "tags": [
          "locations"
        ],
        "summary": "List and filter locations",
        "parameters": [
          {
            "name": "area",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "city",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "business_type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "service",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "max_price",
            "in": "query",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "booking_provider",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "online_booking",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "attribute",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "open_day",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching verified locations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer"
                    },
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Location"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/locations/{location_id}": {
      "get": {
        "tags": [
          "locations"
        ],
        "summary": "Get one verified location",
        "parameters": [
          {
            "name": "location_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^loc_[a-z0-9_]+$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Location with provenance",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Location"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/locations/{location_id}/analysis": {
      "get": {
        "tags": [
          "analysis"
        ],
        "summary": "Get aggregate analysis for a location",
        "parameters": [
          {
            "name": "location_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^loc_[a-z0-9_]+$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Derived signals without raw content",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AnalysisObservation"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/search": {
      "get": {
        "tags": [
          "locations"
        ],
        "summary": "Natural-language search",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "area",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "city",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "business_type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "service",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "max_price",
            "in": "query",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "booking_provider",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "online_booking",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "attribute",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "open_day",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching verified locations"
          },
          "400": {
            "description": "q is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/services": {
      "get": {
        "tags": [
          "locations"
        ],
        "summary": "List normalized observed services",
        "parameters": [
          {
            "name": "area",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Services and observed price ranges"
          }
        }
      }
    },
    "/v1/changes": {
      "get": {
        "tags": [
          "changes"
        ],
        "summary": "List field-level snapshot changes",
        "parameters": [
          {
            "name": "snapshot_from",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "snapshot_to",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "location_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "operation",
            "in": "query",
            "schema": {
              "enum": [
                "add",
                "remove",
                "replace"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Change events",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer"
                    },
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ChangeEvent"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/analysis": {
      "get": {
        "tags": [
          "analysis"
        ],
        "summary": "List aggregate analysis observations",
        "parameters": [
          {
            "name": "location_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "source_platform",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "source_kind",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Derived aggregate signals",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AnalysisObservation"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/corrections": {
      "post": {
        "tags": [
          "corrections"
        ],
        "summary": "Submit a correction for local review",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "location_id",
                  "field_path",
                  "source_url",
                  "note"
                ],
                "properties": {
                  "location_id": {
                    "type": "string"
                  },
                  "field_path": {
                    "type": "string"
                  },
                  "suggested_value": {},
                  "source_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "note": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Queued correction"
          },
          "400": {
            "description": "Invalid correction",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
