content: ' filepath: src/jwplatform_client.brs
  
  ' Constants
  JWPLATFORM_API_HOST = "api.jwplayer.com"
  JWPLATFORM_API_PORT = 443
  USER_AGENT = "jwplatform_client-brightscript/1.0"
  UPLOAD_RETRY_ATTEMPTS = 3
  
  ' JWPlatformClient "constructor"
  function JWPlatformClient(secret = invalid as Dynamic, host = invalid as Dynamic) as Object
      if host = invalid then host = JWPLATFORM_API_HOST
  
      client = {
          _api_secret: secret
          _host: host
          analytics: AnalyticsClient()
          advertising: AdvertisingClient()
          media: MediaClient()
          site: SiteClient()
          playlist: PlaylistClient()
          thumbnail: ThumbnailClient()
          request: JWPlatformClient_request
          requestWithRetry: JWPlatformClient_requestWithRetry
      }
      return client
  end function
  
  ' Raw HTTP request
  function JWPlatformClient_rawRequest(self as Object, method as String, url as String, body = invalid, headers = invalid) as Object
      if headers = invalid then headers = {}
      req = CreateObject("roUrlTransfer")
      req.SetUrl("https://" + self._host + url)
      for each key in headers
          req.AddHeader(key, headers[key])
      end for
      if body <> invalid then
          req.SetRequest("POST")
          req.SetMessagePort(CreateObject("roMessagePort"))
          req.AsyncPostFromString(body)
      end if
      response = req.GetToString()
      status = req.GetResponseCode()
      if status >= 200 and status <= 299 then
          return ParseJson(response)
      else
          ' Raise error (simulate APIError)
          print "API Error: "; status
          return invalid
      end if
  end function
  
  ' Main request method
  function JWPlatformClient_request(self as Object, method as String, path as String, body = invalid, headers = invalid, queryParams = invalid) as Object
      if headers = invalid then headers = {}
      if not headers.DoesExist("User-Agent") then headers["User-Agent"] = USER_AGENT
      if not headers.DoesExist("Authorization") and self._api_secret <> invalid then
          headers["Authorization"] = "Bearer " + self._api_secret
      end if
      if not headers.DoesExist("Content-Type") then headers["Content-Type"] = "application/json"
      if body <> invalid then body = FormatJson(body)
      if queryParams <> invalid then
          path = path + "?" + JWPlatformClient_urlencode(queryParams)
      end if
      return JWPlatformClient_rawRequest(self, method, path, body, headers)
  end function
  
  ' Retry logic
  function JWPlatformClient_requestWithRetry(self as Object, method as String, path as String, body = invalid, headers = invalid, queryParams = invalid, retryAttempts = 3) as Object
      retryCount = 0
      while retryCount < retryAttempts
          response = JWPlatformClient_request(self, method, path, body, headers, queryParams)
          if response <> invalid then return response
          retryCount = retryCount + 1
      end while
      print "Exceeded maximum number of retries"
      return invalid
  end function
  
  ' Helper to URL encode query params
  function JWPlatformClient_urlencode(params as Object) as String
      result = ""
      for each key in params
          if result <> "" then result = result + "&"
          result = result + key + "=" + params[key]
      end for
      return result
  end function
  
  ' Example AnalyticsClient
  function AnalyticsClient() as Object
      return {
          query: function(site_id as String, body as Object, queryParams = invalid)
              return m.top.request("POST", "/v2/sites/" + site_id + "/analytics/queries/", body, invalid, queryParams)
          end function
      }
  end function
  
  ' Example AdvertisingClient
  function AdvertisingClient() as Object
      return {}
  end function
  
  ' Example MediaClient
  function MediaClient() as Object
      return {}
  end function
  
  ' Example SiteClient
  function SiteClient() as Object
      return {}
  end function
  
  ' Example PlaylistClient
  function PlaylistClient() as Object
      return {}
  end function
  
  ' Example ThumbnailClient
  function ThumbnailClient() as Object
      return {}
  end function
  
  ' Usage:
  ' client = JWPlatformClient("YOUR_API_SECRET")
  ' response = client.request("GET", "/v2/sites/your_site_id/media/")