{
  "openapi": "3.0.3",
  "info": {
    "title": "BalochiWords Dictionary API",
    "version": "1.0.0",
    "description": "Read-only JSON API exposing the Balochi–English dictionary for search engines, AI systems, and external integrations.",
    "contact": {
      "name": "BalochiWords",
      "url": "https://balochiwords.com"
    },
    "license": {
      "name": "Free for personal, educational, and research use"
    }
  },
  "servers": [
    {
      "url": "https://balochiwords.com",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "Dictionary",
      "description": "Word lookup and search"
    },
    {
      "name": "Discovery",
      "description": "Metadata and service info"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "summary": "Service health check",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "example": {
                  "status": "ok",
                  "service": "balochiwords-api",
                  "time": "2026-06-14T00:00:00.000Z"
                }
              }
            }
          }
        }
      }
    },
    "/api/metadata": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "summary": "Dataset metadata",
        "responses": {
          "200": {
            "description": "Dictionary metadata and counts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Metadata"
                }
              }
            }
          }
        }
      }
    },
    "/api/languages": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "summary": "Supported languages and pairs",
        "responses": {
          "200": {
            "description": "List of supported languages"
          }
        }
      }
    },
    "/api/public/search": {
      "get": {
        "tags": [
          "Dictionary"
        ],
        "summary": "Search dictionary entries",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "dir",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "en-bal",
                "bal-en"
              ]
            },
            "description": "Optional direction filter; default = both"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid query"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/api/suggest": {
      "get": {
        "tags": [
          "Dictionary"
        ],
        "summary": "Autocomplete suggestions (prefix match)",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 50
            }
          },
          {
            "name": "dir",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "en-bal",
                "bal-en"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 25,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Suggestions"
          }
        }
      }
    },
    "/api/random-word": {
      "get": {
        "tags": [
          "Dictionary"
        ],
        "summary": "Random dictionary entry",
        "parameters": [
          {
            "name": "dir",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "en-bal",
                "bal-en"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A random word"
          }
        }
      }
    },
    "/api/public/word/{slug}": {
      "get": {
        "tags": [
          "Dictionary"
        ],
        "summary": "Fetch all entries sharing a slug",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Word entries"
          },
          "404": {
            "description": "Word not found"
          }
        }
      }
    },
    "/api/public/entry/{id}": {
      "get": {
        "tags": [
          "Dictionary"
        ],
        "summary": "Fetch a curated DB entry by UUID",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Entry"
          },
          "404": {
            "description": "Entry not found or archived"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Metadata": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "website": {
            "type": "string",
            "format": "uri"
          },
          "counts": {
            "type": "object",
            "properties": {
              "uniqueWords": {
                "type": "integer"
              },
              "totalEntries": {
                "type": "integer"
              },
              "translations": {
                "type": "integer"
              }
            }
          }
        }
      },
      "SearchResult": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "word": {
            "type": "string"
          },
          "translations": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "direction": {
            "type": "string",
            "enum": [
              "en-bal",
              "bal-en"
            ]
          },
          "language": {
            "type": "string"
          },
          "url": {
            "type": "string"
          }
        }
      },
      "SearchResponse": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string"
          },
          "direction": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "offset": {
            "type": "integer"
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SearchResult"
            }
          }
        }
      }
    }
  }
}