{
  "openapi": "3.1.0",
  "info": {
    "title": "ProductWatch Compatibility Registry API",
    "version": "1.0.0",
    "description": "Resolve a free-text product string to canonical models and their compatibility attributes."
  },
  "servers": [
    {
      "url": "/api/public/v1"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "CompatEntry": {
        "type": "object",
        "properties": {
          "compatible": {
            "type": "boolean",
            "description": "Whether this strap type is known to fit."
          },
          "size_mm": {
            "oneOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "Strap width in mm. For apple_slide, the band-size family such as '38/40/41'."
          },
          "note": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "compatible",
          "size_mm",
          "note"
        ]
      },
      "ProductCompatibility": {
        "type": "object",
        "properties": {
          "quickfit": {
            "$ref": "#/components/schemas/CompatEntry"
          },
          "quick_release": {
            "$ref": "#/components/schemas/CompatEntry"
          },
          "nato": {
            "$ref": "#/components/schemas/CompatEntry"
          },
          "apple_slide": {
            "$ref": "#/components/schemas/CompatEntry"
          },
          "velcro": {
            "$ref": "#/components/schemas/CompatEntry"
          },
          "other_comments": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "quickfit",
          "quick_release",
          "nato",
          "apple_slide",
          "velcro",
          "other_comments"
        ]
      },
      "Model": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "canonical_name": {
            "type": "string"
          },
          "brand": {
            "type": "string"
          },
          "aliases": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "current",
              "discontinued",
              "announced"
            ]
          },
          "case_size_mm": {
            "type": [
              "number",
              "null"
            ]
          },
          "lug_width_mm": {
            "type": [
              "number",
              "null"
            ]
          },
          "release_year": {
            "type": [
              "integer",
              "null"
            ]
          },
          "product_compatibility": {
            "$ref": "#/components/schemas/ProductCompatibility"
          },
          "source_urls": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "score": {
            "type": "number",
            "description": "Search rank score; present on search results."
          }
        },
        "required": [
          "id",
          "slug",
          "canonical_name",
          "brand",
          "aliases",
          "status",
          "case_size_mm",
          "lug_width_mm",
          "release_year",
          "product_compatibility",
          "source_urls"
        ]
      },
      "SizeOption": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string"
          },
          "canonical_name": {
            "type": "string"
          },
          "case_size_mm": {
            "type": [
              "number",
              "null"
            ]
          },
          "lug_width_mm": {
            "type": [
              "number",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "current",
              "discontinued",
              "announced"
            ]
          }
        }
      },
      "SearchResponse": {
        "type": "object",
        "properties": {
          "dataset": {
            "type": "string"
          },
          "query": {
            "type": "string"
          },
          "count": {
            "type": "integer"
          },
          "ambiguous": {
            "type": "boolean"
          },
          "size_ambiguous": {
            "type": "boolean"
          },
          "size_options": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SizeOption"
            }
          },
          "hint": {
            "type": "string"
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Model"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/datasets": {
      "get": {
        "summary": "List available datasets and their attribute schemas",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/{dataset}/search": {
      "get": {
        "summary": "Ranked fuzzy search for models matching a free-text query",
        "parameters": [
          {
            "name": "dataset",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "watches"
          },
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "does this fit a fenix 7 pro?"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 25,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked candidates",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          }
        }
      }
    },
    "/{dataset}/models/{slug}": {
      "get": {
        "summary": "Full record for one model in the table shape (product_compatibility map)",
        "parameters": [
          {
            "name": "dataset",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Model"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    }
  }
}