module TD.Data.ProfileTab
  (ProfileTab(..)) where

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

-- | Describes a tab shown in a user or a chat profile
data ProfileTab
  = ProfileTabPosts -- ^ A tab with stories posted by the user or the channel chat and saved to profile
  | ProfileTabGifts -- ^ A tab with gifts received by the user or the channel chat
  | ProfileTabMedia -- ^ A tab with photos and videos posted by the channel
  | ProfileTabFiles -- ^ A tab with documents posted by the channel
  | ProfileTabLinks -- ^ A tab with messages posted by the channel and containing links
  | ProfileTabMusic -- ^ A tab with audio messages posted by the channel
  | ProfileTabVoice -- ^ A tab with voice notes posted by the channel
  | ProfileTabGifs -- ^ A tab with animations posted by the channel
  deriving (ProfileTab -> ProfileTab -> Bool
(ProfileTab -> ProfileTab -> Bool)
-> (ProfileTab -> ProfileTab -> Bool) -> Eq ProfileTab
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProfileTab -> ProfileTab -> Bool
== :: ProfileTab -> ProfileTab -> Bool
$c/= :: ProfileTab -> ProfileTab -> Bool
/= :: ProfileTab -> ProfileTab -> Bool
Eq, Int -> ProfileTab -> ShowS
[ProfileTab] -> ShowS
ProfileTab -> String
(Int -> ProfileTab -> ShowS)
-> (ProfileTab -> String)
-> ([ProfileTab] -> ShowS)
-> Show ProfileTab
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProfileTab -> ShowS
showsPrec :: Int -> ProfileTab -> ShowS
$cshow :: ProfileTab -> String
show :: ProfileTab -> String
$cshowList :: [ProfileTab] -> ShowS
showList :: [ProfileTab] -> ShowS
Show)

instance I.ShortShow ProfileTab where
  shortShow :: ProfileTab -> String
shortShow ProfileTab
ProfileTabPosts
      = String
"ProfileTabPosts"
  shortShow ProfileTab
ProfileTabGifts
      = String
"ProfileTabGifts"
  shortShow ProfileTab
ProfileTabMedia
      = String
"ProfileTabMedia"
  shortShow ProfileTab
ProfileTabFiles
      = String
"ProfileTabFiles"
  shortShow ProfileTab
ProfileTabLinks
      = String
"ProfileTabLinks"
  shortShow ProfileTab
ProfileTabMusic
      = String
"ProfileTabMusic"
  shortShow ProfileTab
ProfileTabVoice
      = String
"ProfileTabVoice"
  shortShow ProfileTab
ProfileTabGifs
      = String
"ProfileTabGifs"

instance AT.FromJSON ProfileTab where
  parseJSON :: Value -> Parser ProfileTab
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
"profileTabPosts" -> ProfileTab -> Parser ProfileTab
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProfileTab
ProfileTabPosts
      String
"profileTabGifts" -> ProfileTab -> Parser ProfileTab
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProfileTab
ProfileTabGifts
      String
"profileTabMedia" -> ProfileTab -> Parser ProfileTab
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProfileTab
ProfileTabMedia
      String
"profileTabFiles" -> ProfileTab -> Parser ProfileTab
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProfileTab
ProfileTabFiles
      String
"profileTabLinks" -> ProfileTab -> Parser ProfileTab
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProfileTab
ProfileTabLinks
      String
"profileTabMusic" -> ProfileTab -> Parser ProfileTab
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProfileTab
ProfileTabMusic
      String
"profileTabVoice" -> ProfileTab -> Parser ProfileTab
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProfileTab
ProfileTabVoice
      String
"profileTabGifs"  -> ProfileTab -> Parser ProfileTab
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProfileTab
ProfileTabGifs
      String
_                 -> Parser ProfileTab
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser ProfileTab
forall a. Monoid a => a
mempty

instance AT.ToJSON ProfileTab where
  toJSON :: ProfileTab -> Value
toJSON ProfileTab
ProfileTabPosts
      = [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
"profileTabPosts"
        ]
  toJSON ProfileTab
ProfileTabGifts
      = [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
"profileTabGifts"
        ]
  toJSON ProfileTab
ProfileTabMedia
      = [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
"profileTabMedia"
        ]
  toJSON ProfileTab
ProfileTabFiles
      = [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
"profileTabFiles"
        ]
  toJSON ProfileTab
ProfileTabLinks
      = [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
"profileTabLinks"
        ]
  toJSON ProfileTab
ProfileTabMusic
      = [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
"profileTabMusic"
        ]
  toJSON ProfileTab
ProfileTabVoice
      = [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
"profileTabVoice"
        ]
  toJSON ProfileTab
ProfileTabGifs
      = [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
"profileTabGifs"
        ]