info:
  name: Field Values Search - Series
  type: http
  seq: 9

http:
  method: GET
  url: "{{base_url}}/api/media-items/search?library_id={{library_id}}&series=foundation&limit=50"
  params:
    - name: library_id
      value: "{{library_id}}"
      type: query
    - name: series
      value: foundation
      type: query
    - name: limit
      value: "50"
      type: query
  auth: inherit

settings:
  encodeUrl: true
  timeout: 0
  followRedirects: true
  maxRedirects: 5

docs: |-
  ## Field Values Search - Series

  Fetches distinct series values for autocomplete dropdowns with counts and similarity scores.

  **Method:** GET

  **Endpoint:** /api/media-items/search

  **Authentication:** Required (Bearer token)

  **Query Parameters:**
  - `library_id` (string, required): Library UUID to search within
  - `series` (string, required): Series name to search for (fuzzy match)
  - `limit` (integer, optional): Maximum results to return (default: 50)

  **How It Works:**
  - Returns distinct series names from the library
  - Fuzzy matches the search query against series names
  - Includes count of books per series
  - Includes similarity score (0-1, higher = better match)
  - Sorted by similarity score, then by count

  **Use Case:**
  - Populate autocomplete dropdown when user types in series filter field
  - Show user available series with book counts
  - Help users discover similar series names

  **Response:** HTTP 200 (OK)
  ```json
  {
    "results": [
      {
        "value": "Foundation",
        "count": 7,
        "score": 0.9
      },
      {
        "value": "Foundation Series",
        "count": 7,
        "score": 0.85
      }
    ],
    "total": 2
  }
  ```

  **Examples:**
  - `series=foundation` → Returns "Foundation" (7 books), "Foundation Series" (7 books)
  - `series=harry` → Returns "Harry Potter" (10 books)
  - `series=lord` → Returns "Lord of the Rings" (3 books)

  **Frontend Integration:**
  - Call this endpoint when user types ≥2 characters in series field
  - Display results in `<datalist>` or custom dropdown
  - Show: "Series Name (count)" format
  - Allow user to select from suggestions

  **Success Criteria:**
  - Status: 200
  - Returns array of series values with counts
  - Results sorted by relevance (similarity score)
  - Only returns series matching the fuzzy search
