{
  "openapi": "3.1.0",
  "info": {
    "title": "StreamSearch Up Public Search API",
    "version": "0.1.0"
  },
  "servers": [
    {
      "url": "/api"
    }
  ],
  "security": [],
  "paths": {
    "/countries": {
      "get": {
        "operationId": "listCountries",
        "tags": [
          "streaming"
        ],
        "summary": "List supported countries",
        "description": "Returns the list of countries supported for streaming availability lookups.",
        "responses": {
          "200": {
            "description": "List of countries",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Country"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/search": {
      "get": {
        "operationId": "searchTitles",
        "tags": [
          "streaming"
        ],
        "summary": "Search movies and TV shows with streaming availability",
        "description": "Searches the local title catalogue, preserving originals and remakes,\nand enriches results with streaming availability in the chosen country.\nPublic and usable without login or an API key. Automated clients should\nsend X-StreamSearch-Client: agent. Recognized automated User-Agents also\nuse agent mode: cached streaming links first, then TMDB fallback, without\ntriggering paid Watchmode refreshes. An empty sources list is not proof\nthat a title is unavailable everywhere.\n",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "description": "Search query (movie or TV show title)",
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "country",
            "in": "query",
            "required": true,
            "description": "Two-letter ISO country code (uppercase), e.g. US, GB, CA",
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 2
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "Upstream provider error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/title": {
      "get": {
        "operationId": "getTitle",
        "tags": [
          "streaming"
        ],
        "summary": "Look up a single title by ID with streaming availability",
        "description": "Returns details and streaming availability for a single Watchmode title\nin the requested country. Used for shareable deep links.\nPublic and usable without login or an API key. Automated clients should\nsend X-StreamSearch-Client: agent. Agent requests use cached streaming\nlinks or TMDB fallback and do not trigger paid Watchmode refreshes.\n",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "Watchmode title ID",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "country",
            "in": "query",
            "required": true,
            "description": "Two-letter ISO country code (uppercase), e.g. US, GB, CA",
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 2
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Title details with streaming sources",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TitleResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Title not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "Upstream provider error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Country": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "Two-letter ISO country code"
          },
          "name": {
            "type": "string",
            "description": "Human-readable country name"
          }
        },
        "required": [
          "code",
          "name"
        ]
      },
      "SearchResponse": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TitleResult"
            }
          }
        },
        "required": [
          "query",
          "country",
          "results"
        ]
      },
      "TitleResult": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Watchmode title ID"
          },
          "title": {
            "type": "string"
          },
          "year": {
            "type": [
              "integer",
              "null"
            ]
          },
          "type": {
            "type": "string",
            "description": "Title type — movie, tv_series, tv_special, tv_miniseries, short_film"
          },
          "imdbId": {
            "type": [
              "string",
              "null"
            ]
          },
          "tmdbId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "tmdbType": {
            "type": [
              "string",
              "null"
            ]
          },
          "sources": {
            "type": "array",
            "description": "Streaming sources available in the requested country",
            "items": {
              "$ref": "#/components/schemas/StreamingSource"
            }
          }
        },
        "required": [
          "id",
          "title",
          "year",
          "type",
          "sources"
        ]
      },
      "StreamingSource": {
        "type": "object",
        "properties": {
          "sourceId": {
            "type": "integer",
            "description": "Watchmode source ID"
          },
          "name": {
            "type": "string",
            "description": "Streaming service name (e.g. Netflix, Disney+)"
          },
          "type": {
            "type": "string",
            "description": "Type of access — sub (subscription), free, buy, rent, tve (cable login)",
            "enum": [
              "sub",
              "free",
              "buy",
              "rent",
              "tve"
            ]
          },
          "webUrl": {
            "type": [
              "string",
              "null"
            ],
            "description": "Direct URL to watch on the service, when available"
          },
          "format": {
            "type": [
              "string",
              "null"
            ],
            "description": "Video format such as HD, 4K, SD"
          },
          "price": {
            "type": [
              "number",
              "null"
            ],
            "description": "Price for buy/rent in USD"
          },
          "seasons": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Number of seasons available (TV only)"
          },
          "episodes": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Number of episodes available (TV only)"
          }
        },
        "required": [
          "sourceId",
          "name",
          "type"
        ]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      }
    }
  }
}
