info:
  name: Create Saved Filter
  type: http
  seq: 2
http:
  method: POST
  url: '{{base_url}}/api/saved-filters'
  auth: inherit
  body:
    type: json
    jsonBody: "{\n    \"name\": \"My Sci-Fi Books\",\n    \"resource_type\":\
      \ \"media-items\",\n    \"filters\": {\n      \"genre_filter\": \"Science Fiction\"\
      ,\n      \"sort\": \"title ASC\",\n      \"author_filter\": \"\"\n    }\n\
      }"

docs: |-
  ## Create Saved Filter

  Creates a new saved filter for the authenticated user.

  **Method:** POST

  **Endpoint:** /api/saved-filters

  **Authentication:** Required (Bearer token)

  **Request Body:**
  ```json
  {
    "name": "My Sci-Fi Books",
    "resource_type": "media-items",
    "filters": {
      "genre_filter": "Science Fiction",
      "sort": "title ASC",
      "author_filter": "",
      "series_filter": ""
    }
  }
  ```

  **Required Fields:**
  - `name` (string, required): Filter name
    - Must be unique per user + resource type combination
    - Maximum 100 characters
    - Cannot be empty
  - `resource_type` (string, required): Type of resource to filter
    - Examples: "media-items", "collections", "devices"
    - Must match valid resource types
  - `filters` (object, required): Key-value pairs of filter criteria
    - Flexible structure - any valid filter fields
    - Serialized as JSONB in database

  **Common Filter Fields for media-items:**
  - `search`: General search term
  - `author_filter`: Filter by author name
  - `genre_filter`: Filter by genre
  - `series_filter`: Filter by series
  - `language_filter`: Filter by language
  - `year_min`: Minimum copyright year
  - `year_max`: Maximum copyright year
  - `has_cover`: Boolean for cover image
  - `sort`: Sort order (e.g., "title ASC", "created_at DESC")

  **Response:**
  ```json
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "My Sci-Fi Books",
    "resource_type": "media-items",
    "filters": {
      "genre_filter": "Science Fiction",
      "sort": "title ASC"
    },
    "created_at": "2024-03-20T12:00:00Z",
    "updated_at": "2024-03-20T12:00:00Z"
  }
  ```

  **Status Codes:**
  - 201: Created - Filter successfully created
  - 400: Bad Request - Invalid request body or missing required fields
  - 401: Unauthorized - Invalid or missing authentication token
  - 409: Conflict - Filter with this name already exists for this resource type

  **Error Response Examples:**

  Duplicate name error:
  ```json
  {
    "error": "filter with name 'My Sci-Fi Books' already exists for this resource type"
  }
  ```

  **Example Usage:**
  ```bash
  curl -X POST \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "My Sci-Fi Books",
      "resource_type": "media-items",
      "filters": {
        "genre_filter": "Science Fiction",
        "sort": "title ASC"
      }
    }' \
    "{{base_url}}/api/saved-filters"
  ```

  **Validation Rules:**
  - Name must be unique per user + resource type
  - Name cannot be empty or whitespace only
  - Resource type must be valid
  - Filters object must be provided (can be empty object {})
