-- | Access the @/projects@ endpoint.
--
-- Example:
--
-- @
-- >>> import Web.Pagure
-- >>> let pc = PagureConfig "https://pagure.io" Nothing
-- >>> runPagureT (projects Nothing (Just "codeblock") Nothing) pc
-- @
projects ::
  Maybe Tag -- ^ Tags
  -> Maybe Username -- ^ Username
  -> Maybe Bool -- ^ Fork
  -> PagureT ProjectsResponse
projects t u f = do
  opts <- pagureWreqOptions
  let opts' = opts & param "tags" .~ maybeToList t
                   & param "username" .~ maybeToList u
                   & param "fork" .~ [maybeToBoolString f]
  resp <- asJSON =<< pagureGetWith opts' ("/projects")
  return (resp ^. responseBody)
  where
    maybeToBoolString (Just True)  = "true"
    maybeToBoolString (Just False) = "false"
    maybeToBoolString Nothing      = "false"
projects ::
  Maybe Tag -- ^ Tags
  -> Maybe Username -- ^ Username
  -> Maybe Bool -- ^ Fork
  -> PagureT ProjectsResponse
projects t u f = do
  opts <- pagureWreqOptions
  let opts' = opts & param "tags" .~ maybeToList t
                   & param "username" .~ maybeToList u
                   & param "fork" .~ [maybeToBoolString f]
  resp <- asJSON =<< pagureGetWith opts' ("/projects")
  return (resp ^. responseBody)
  where
    maybeToBoolString (Just True)  = "true"
    maybeToBoolString (Just False) = "false"
    maybeToBoolString Nothing      = "false"
projects t u f = do
  opts <- pagureWreqOptions
  let opts' = opts & param "tags" .~ maybeToList t
                   & param "username" .~ maybeToList u
                   & param "fork" .~ [maybeToBoolString f]
  resp <- asJSON =<< pagureGetWith opts' ("/projects")
  return (resp ^. responseBody)
  where
    maybeToBoolString (Just True)  = "true"
    maybeToBoolString (Just False) = "false"
    maybeToBoolString Nothing      = "false"