modules:
  jellyfin_client_count:
    # Your original, simple SQL query
    body:
      content: |
        {
          "CustomQueryString": "SELECT ClientName, COUNT(ClientName) AS Count FROM PlaybackActivity WHERE UserId != '5d9eadb456d14511b268c9eddcbeb0b8' GROUP BY ClientName ORDER BY Count DESC;"
        }
    headers:
      Content-Type: "application/json"
      Authorization: "MediaBrowser Token="
    metrics:
      - name: jellyfin_client_playback_count
        help: Total playback count per client (excluding specified user)
        type: object
        path: "{ $.results[*] }"  # Iterates over the array, e.g., ["Jellyfin Web", 488]
        labels:
          client: "{ [0] }"      # <-- CORRECT SYNTAX: Gets index 0
        values:
          value: "{ [1] }"       # <-- CORRECT SYNTAX: Gets index 1

  jellyfin_client_duration:
    body:
      content: |
        {
          "CustomQueryString": "SELECT ClientName, SUM(PlayDuration) AS Count FROM PlaybackActivity WHERE UserId != '5d9eadb456d14511b268c9eddcbeb0b8' AND PlayDuration > 0 GROUP BY ClientName ORDER BY Count DESC;"
        }
    headers:
      Content-Type: "application/json"
      Authorization: "MediaBrowser Token="
    metrics:
      - name: jellyfin_client_playback_duration_seconds
        help: Total playback duration per client in seconds (excluding specified user)
        type: object
        path: "{ $.results[*] }"
        labels:
          client: "{ [0] }"
        values:
          value: "{ [1] }"

  jellyfin_weekday_duration:
    body:
      content: |
        {
          "CustomQueryString": "SELECT strftime('%w', DateCreated) AS Weekday, SUM(PlayDuration) AS TotalPlayDuration FROM PlaybackActivity WHERE UserId != '5d9eadb456d14511b268c9eddcbeb0b8' AND PlayDuration > 0 GROUP BY strftime('%w', DateCreated) ORDER BY strftime('%w', DateCreated);"
        }
    headers:
      Content-Type: "application/json"
      Authorization: "MediaBrowser Token=02c869f338904f1daab13ae9312b6718"
    metrics:
      - name: jellyfin_weekday_playback_duration_seconds
        help: Total playback duration per weekday in seconds (excluding specified user)
        type: object
        path: "{ $.results[*] }"
        labels:
          weekday: "{ [0] }"
        values:
          value: "{ [1] }"

  jellyfin_hourly_duration:
    body:
      content: |
        {
          "CustomQueryString": "SELECT strftime('%H', DateCreated) AS HourOfDay, SUM(PlayDuration) AS TotalDuration FROM PlaybackActivity WHERE UserId != '5d9eadb456d14511b268c9eddcbeb0b8' AND PlayDuration > 0 GROUP BY HourOfDay ORDER BY HourOfDay;"
        }
    headers:
      Content-Type: "application/json"
      Authorization: "MediaBrowser Token="
    metrics:
      - name: jellyfin_hourly_playback_duration_seconds
        help: Total playback duration per hour of day in seconds (excluding specified user)
        type: object
        path: "{ $.results[*] }"
        labels:
          hour: "{ [0] }"
        values:
          value: "{ [1] }"