-- | Contains actions which are applicable to both Posts and Comments,
--   like replying, deleting and reporting.
module Reddit.Actions.Thing
  ( Reddit.Actions.Thing.reply
  , Reddit.Actions.Thing.delete
  , Reddit.Actions.Thing.report ) where

import Reddit.Types
import Reddit.Types.Empty
import Reddit.Types.Reddit
import qualified Reddit.Routes.Thing as Route

import Data.Text (Text)

-- | Reply to a something (a post \/ comment \/ message)
reply :: (Monad m, Thing a)
      => a -- ^ Thing to reply to
      -> Text -- ^ Response contents
      -> RedditT m CommentID
reply :: a -> Text -> RedditT m CommentID
reply a
t Text
b = do
  POSTWrapped CommentID
res <- Route -> RedditT m (POSTWrapped CommentID)
forall a (m :: * -> *).
(FromJSON a, Monad m) =>
Route -> RedditT m a
runRoute (Route -> RedditT m (POSTWrapped CommentID))
-> Route -> RedditT m (POSTWrapped CommentID)
forall a b. (a -> b) -> a -> b
$ a -> Text -> Route
forall a. Thing a => a -> Text -> Route
Route.reply a
t Text
b
  CommentID -> RedditT m CommentID
forall (m :: * -> *) a. Monad m => a -> m a
return CommentID
res

-- | Delete something you created. Note that this is different to removing
--   a post / comment as a moderator action. Deleting something you don't
--   own won't error (but naturally won't delete anything either).
delete :: (Monad m, Thing a)
       => a -- ^ Thing to delete
       -> RedditT m ()
delete :: a -> RedditT m ()
delete = RedditT m Empty -> RedditT m ()
forall (m :: * -> *). Monad m => m Empty -> m ()
nothing (RedditT m Empty -> RedditT m ())
-> (a -> RedditT m Empty) -> a -> RedditT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Route -> RedditT m Empty
forall a (m :: * -> *).
(FromJSON a, Monad m) =>
Route -> RedditT m a
runRoute (Route -> RedditT m Empty) -> (a -> Route) -> a -> RedditT m Empty
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Route
forall a. Thing a => a -> Route
Route.delete

-- | Report something.
report :: (Monad m, Thing a)
       => a -- ^ Thing to report
       -> Text -- ^ Reason for reporting
       -> RedditT m ()
report :: a -> Text -> RedditT m ()
report a
t Text
r = 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
$ a -> Text -> Route
forall a. Thing a => a -> Text -> Route
Route.report a
t Text
r