info:
  name: Complete CRUD Workflow
  type: http
  seq: 4
http:
  method: POST
  url: '{{base_url}}/api/saved-filters'
  auth: inherit
  body:
    type: json
    jsonBody: "{\n    \"name\": \"Complete Workflow Test\",\n    \"resource_type\"\
      : \"media-items\",\n    \"filters\": {\n      \"genre_filter\": \"Science Fiction\"\
      ,\n      \"sort\": \"title ASC\"\n    }\n  }"

docs: |-
  ## Complete CRUD Workflow

  End-to-end test demonstrating the complete lifecycle of a saved filter: Create → Read → Update → Delete.

  **Workflow Steps:**

  **Step 1: CREATE a new filter**
  ```bash
  CREATE_RESPONSE=$(curl -s -X POST \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Complete Workflow Test",
      "resource_type": "media-items",
      "filters": {
        "genre_filter": "Science Fiction",
        "sort": "title ASC"
      }
    }' \
    "{{base_url}}/api/saved-filters")

  echo "Create Response:"
  echo $CREATE_RESPONSE | jq '.'

  # Extract filter ID for subsequent requests
  FILTER_ID=$(echo $CREATE_RESPONSE | jq -r '.id')
  echo "Created filter ID: $FILTER_ID"

  # Expected Status: 201 Created
  # Expected Response:
  # {
  #   "id": "550e8400-e29b-41d4-a716-446655440000",
  #   "name": "Complete Workflow Test",
  #   "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"
  # }
  ```

  **Step 2: READ the created filter (list all)**
  ```bash
  # List all filters for media-items
  LIST_RESPONSE=$(curl -s \
    -H "Authorization: Bearer YOUR_TOKEN" \
    "{{base_url}}/api/saved-filters?resource_type=media-items")

  echo "List Response:"
  echo $LIST_RESPONSE | jq '.'

  # Verify our filter is in the list
  FILTER_EXISTS=$(echo $LIST_RESPONSE | jq --arg id "$FILTER_ID" \
    '.[] | select(.id == $id) | .id')

  if [ "$FILTER_EXISTS" == "$FILTER_ID" ]; then
    echo "✓ Filter found in list"
  else
    echo "✗ Filter NOT found in list"
  fi

  # Expected Status: 200 OK
  # Expected Response: Array containing our newly created filter
  ```

  **Step 3: UPDATE the filter**
  ```bash
  # Update filter name and criteria
  UPDATE_RESPONSE=$(curl -s -X PUT \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Complete Workflow Test - Updated",
      "resource_type": "media-items",
      "filters": {
        "genre_filter": "Science Fiction Fantasy",
        "sort": "author ASC",
        "year_min": "2000"
      }
    }' \
    "{{base_url}}/api/saved-filters/$FILTER_ID")

  echo "Update Response:"
  echo $UPDATE_RESPONSE | jq '.'

  # Verify updated_at timestamp changed
  UPDATED_AT=$(echo $UPDATE_RESPONSE | jq -r '.updated_at')
  echo "Filter updated at: $UPDATED_AT"

  # Expected Status: 200 OK
  # Expected Response:
  # {
  #   "id": "550e8400-e29b-41d4-a716-446655440000",
  #   "name": "Complete Workflow Test - Updated",
  #   "resource_type": "media-items",
  #   "filters": {
  #     "genre_filter": "Science Fiction Fantasy",
  #     "sort": "author ASC",
  #     "year_min": "2000"
  #   },
  #   "created_at": "2024-03-20T12:00:00Z",
  #   "updated_at": "2024-03-20T12:05:00Z"  # NEW TIMESTAMP
  # }
  ```

  **Step 4: DELETE the filter**
  ```bash
  # Delete the filter
  DELETE_RESPONSE=$(curl -s -X DELETE \
    -H "Authorization: Bearer YOUR_TOKEN" \
    "{{base_url}}/api/saved-filters/$FILTER_ID")

  echo "Delete Response:"
  echo $DELETE_RESPONSE

  # Expected Status: 204 No Content
  # Expected Response: (empty body)
  if [ -z "$DELETE_RESPONSE" ]; then
    echo "✓ Filter deleted successfully (empty response)"
  fi
  ```

  **Step 5: VERIFY deletion**
  ```bash
  # Try to get the deleted filter
  GET_RESPONSE=$(curl -s \
    -H "Authorization: Bearer YOUR_TOKEN" \
    "{{base_url}}/api/saved-filters?resource_type=media-items")

  echo "List After Delete:"
  echo $GET_RESPONSE | jq '.'

  # Verify filter is NOT in the list
  FILTER_EXISTS=$(echo $GET_RESPONSE | jq --arg id "$FILTER_ID" \
    '.[] | select(.id == $id) | .id')

  if [ -z "$FILTER_EXISTS" ]; then
    echo "✓ Filter successfully deleted (not found in list)"
  else
    echo "✗ Filter still exists (deletion failed)"
  fi

  # Expected: Filter no longer appears in list
  ```

  **Shell Script Complete Example:**
  ```bash
  #!/bin/bash

  set -e  # Exit on error

  BASE_URL="{{base_url}}"
  TOKEN="YOUR_TOKEN"

  echo "=== Complete CRUD Workflow Test ==="
  echo ""

  # 1. CREATE
  echo "Step 1: Creating filter..."
  FILTER_ID=$(curl -s -X POST \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Workflow Test",
      "resource_type": "media-items",
      "filters": {"genre_filter": "Science Fiction"}
    }' \
    "$BASE_URL/api/saved-filters" | jq -r '.id')

  echo "✓ Created filter: $FILTER_ID"
  echo ""

  # 2. READ
  echo "Step 2: Reading filters..."
  curl -s -H "Authorization: Bearer $TOKEN" \
    "$BASE_URL/api/saved-filters?resource_type=media-items" | \
    jq --arg id "$FILTER_ID" '.[] | select(.id == $id)'

  echo "✓ Filter retrieved"
  echo ""

  # 3. UPDATE
  echo "Step 3: Updating filter..."
  curl -s -X PUT \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Workflow Test - Updated",
      "resource_type": "media-items",
      "filters": {"genre_filter": "Fantasy"}
    }' \
    "$BASE_URL/api/saved-filters/$FILTER_ID" | jq '.'

  echo "✓ Filter updated"
  echo ""

  # 4. DELETE
  echo "Step 4: Deleting filter..."
  curl -s -X DELETE \
    -H "Authorization: Bearer $TOKEN" \
    "$BASE_URL/api/saved-filters/$FILTER_ID" -w "\nStatus: %{http_code}\n"

  echo "✓ Filter deleted"
  echo ""

  # 5. VERIFY
  echo "Step 5: Verifying deletion..."
  COUNT=$(curl -s -H "Authorization: Bearer $TOKEN" \
    "$BASE_URL/api/saved-filters?resource_type=media-items" | \
    jq --arg id "$FILTER_ID" '[.[] | select(.id == $id)] | length')

  if [ "$COUNT" -eq 0 ]; then
    echo "✓ Verification successful - filter deleted"
  else
    echo "✗ Verification failed - filter still exists"
    exit 1
  fi

  echo ""
  echo "=== All CRUD operations completed successfully ==="
  ```

  **Success Criteria:**
  - ✅ Create returns 201 with generated ID
  - ✅ Read returns filter in list
  - ✅ Update modifies filter and updates timestamp
  - ✅ Delete returns 204 No Content
  - ✅ Filter no longer appears in list after deletion
