-- | Contains actions for handling flair on a subreddit-wise basis.
module Reddit.Actions.Flair
  ( getFlairList
  , getFlairList'
  , addLinkFlair
  , flairCSV ) where

import Reddit.Routes.Flair
import Reddit.Types.Empty
import Reddit.Types.Flair
import Reddit.Types.Options
import Reddit.Types.Reddit
import Reddit.Types.Subreddit
import Reddit.Types.User

import Control.Monad
import Data.Aeson hiding (Options(..))
import Data.Default.Class
import Data.Text (Text)

-- | Get the flair list for a subreddit. Requires moderator privileges on
--   the subreddit.
getFlairList :: Monad m => SubredditName -> RedditT m FlairListing
getFlairList :: SubredditName -> RedditT m FlairListing
getFlairList = Options UserID -> SubredditName -> RedditT m FlairListing
forall (m :: * -> *).
Monad m =>
Options UserID -> SubredditName -> RedditT m FlairListing
getFlairList' Options UserID
forall a. Default a => a
def

-- | Get the flair list for a subreddit (with 'Options'). Requires moderator
--   privileges on the subreddit.
getFlairList' :: Monad m => Options UserID -> SubredditName -> RedditT m FlairListing
getFlairList' :: Options UserID -> SubredditName -> RedditT m FlairListing
getFlairList' Options UserID
opts SubredditName
r = (FList -> FlairListing)
-> RedditT m FList -> RedditT m FlairListing
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM FList -> FlairListing
flistToListing (RedditT m FList -> RedditT m FlairListing)
-> RedditT m FList -> RedditT m FlairListing
forall a b. (a -> b) -> a -> b
$ Route -> RedditT m FList
forall a (m :: * -> *).
(FromJSON a, Monad m) =>
Route -> RedditT m a
runRoute (Options UserID -> SubredditName -> Route
flairList Options UserID
opts SubredditName
r)

-- | Add link flair to the subreddit-wide template for a subreddit that you moderate.
--   Requires moderator privileges on the subreddit.
addLinkFlair :: Monad m
             => SubredditName -- ^ The subreddit whose template you want to modify
             -> Text -- ^ The intended CSS class of the new link flair
             -> Text -- ^ The intended text label of the new link flair
             -> Bool -- ^ Whether the flair should be editable by users
             -> RedditT m ()
addLinkFlair :: SubredditName -> Text -> Text -> Bool -> RedditT m ()
addLinkFlair SubredditName
r Text
c Text
l Bool
e =
  RedditT m Empty -> RedditT m ()
forall (m :: * -> *). Monad m => m Empty -> m ()
nothing (RedditT m Empty -> RedditT m ())
-> RedditT m Empty -> RedditT m ()
forall a b. (a -> b) -> a -> b
$ Route -> RedditT m Empty
forall a (m :: * -> *).
(FromJSON a, Monad m) =>
Route -> RedditT m a
runRoute (Route -> RedditT m Empty) -> Route -> RedditT m Empty
forall a b. (a -> b) -> a -> b
$ SubredditName -> Text -> Text -> Bool -> Route
addLinkFlairTemplate SubredditName
r Text
c Text
l Bool
e

flairCSV :: Monad m => SubredditName -> [(Username, Text, Text)] -> RedditT m Value
flairCSV :: SubredditName -> [(Username, Text, Text)] -> RedditT m Value
flairCSV SubredditName
r [(Username, Text, Text)]
sets =
  Route -> RedditT m Value
forall a (m :: * -> *).
(FromJSON a, Monad m) =>
Route -> RedditT m a
runRoute (Route -> RedditT m Value) -> Route -> RedditT m Value
forall a b. (a -> b) -> a -> b
$ SubredditName -> [(Username, Text, Text)] -> Route
flairCSVRoute SubredditName
r [(Username, Text, Text)]
sets