module TD.Data.StoryList
  (StoryList(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

-- | Describes a list of stories
data StoryList
  = StoryListMain -- ^ The list of stories, shown in the main chat list and folder chat lists
  | StoryListArchive -- ^ The list of stories, shown in the Arvhive chat list
  deriving (StoryList -> StoryList -> Bool
(StoryList -> StoryList -> Bool)
-> (StoryList -> StoryList -> Bool) -> Eq StoryList
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StoryList -> StoryList -> Bool
== :: StoryList -> StoryList -> Bool
$c/= :: StoryList -> StoryList -> Bool
/= :: StoryList -> StoryList -> Bool
Eq, Int -> StoryList -> ShowS
[StoryList] -> ShowS
StoryList -> String
(Int -> StoryList -> ShowS)
-> (StoryList -> String)
-> ([StoryList] -> ShowS)
-> Show StoryList
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StoryList -> ShowS
showsPrec :: Int -> StoryList -> ShowS
$cshow :: StoryList -> String
show :: StoryList -> String
$cshowList :: [StoryList] -> ShowS
showList :: [StoryList] -> ShowS
Show)

instance I.ShortShow StoryList where
  shortShow :: StoryList -> String
shortShow StoryList
StoryListMain
      = String
"StoryListMain"
  shortShow StoryList
StoryListArchive
      = String
"StoryListArchive"

instance AT.FromJSON StoryList where
  parseJSON :: Value -> Parser StoryList
parseJSON (AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"storyListMain"    -> StoryList -> Parser StoryList
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure StoryList
StoryListMain
      String
"storyListArchive" -> StoryList -> Parser StoryList
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure StoryList
StoryListArchive
      String
_                  -> Parser StoryList
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser StoryList
forall a. Monoid a => a
mempty

instance AT.ToJSON StoryList where
  toJSON :: StoryList -> Value
toJSON StoryList
StoryListMain
      = [Pair] -> Value
A.object
        [ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"storyListMain"
        ]
  toJSON StoryList
StoryListArchive
      = [Pair] -> Value
A.object
        [ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"storyListArchive"
        ]