module TD.Data.BlockList
  (BlockList(..)) where

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

-- | Describes type of block list
data BlockList
  = BlockListMain -- ^ The main block list that disallows writing messages to the current user, receiving their status and photo, viewing of stories, and some other actions
  | BlockListStories -- ^ The block list that disallows viewing of stories of the current user
  deriving (BlockList -> BlockList -> Bool
(BlockList -> BlockList -> Bool)
-> (BlockList -> BlockList -> Bool) -> Eq BlockList
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BlockList -> BlockList -> Bool
== :: BlockList -> BlockList -> Bool
$c/= :: BlockList -> BlockList -> Bool
/= :: BlockList -> BlockList -> Bool
Eq, Int -> BlockList -> ShowS
[BlockList] -> ShowS
BlockList -> String
(Int -> BlockList -> ShowS)
-> (BlockList -> String)
-> ([BlockList] -> ShowS)
-> Show BlockList
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BlockList -> ShowS
showsPrec :: Int -> BlockList -> ShowS
$cshow :: BlockList -> String
show :: BlockList -> String
$cshowList :: [BlockList] -> ShowS
showList :: [BlockList] -> ShowS
Show)

instance I.ShortShow BlockList where
  shortShow :: BlockList -> String
shortShow BlockList
BlockListMain
      = String
"BlockListMain"
  shortShow BlockList
BlockListStories
      = String
"BlockListStories"

instance AT.FromJSON BlockList where
  parseJSON :: Value -> Parser BlockList
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
"blockListMain"    -> BlockList -> Parser BlockList
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BlockList
BlockListMain
      String
"blockListStories" -> BlockList -> Parser BlockList
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BlockList
BlockListStories
      String
_                  -> Parser BlockList
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser BlockList
forall a. Monoid a => a
mempty

instance AT.ToJSON BlockList where
  toJSON :: BlockList -> Value
toJSON BlockList
BlockListMain
      = [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
"blockListMain"
        ]
  toJSON BlockList
BlockListStories
      = [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
"blockListStories"
        ]