module TD.Data.GroupCallId
  (GroupCallId(..)) where

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

data GroupCallId
  = GroupCallId -- ^ Contains the group call identifier
    { GroupCallId -> Maybe Int
_id :: Maybe Int -- ^ Group call identifier
    }
  deriving (GroupCallId -> GroupCallId -> Bool
(GroupCallId -> GroupCallId -> Bool)
-> (GroupCallId -> GroupCallId -> Bool) -> Eq GroupCallId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GroupCallId -> GroupCallId -> Bool
== :: GroupCallId -> GroupCallId -> Bool
$c/= :: GroupCallId -> GroupCallId -> Bool
/= :: GroupCallId -> GroupCallId -> Bool
Eq, Int -> GroupCallId -> ShowS
[GroupCallId] -> ShowS
GroupCallId -> String
(Int -> GroupCallId -> ShowS)
-> (GroupCallId -> String)
-> ([GroupCallId] -> ShowS)
-> Show GroupCallId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GroupCallId -> ShowS
showsPrec :: Int -> GroupCallId -> ShowS
$cshow :: GroupCallId -> String
show :: GroupCallId -> String
$cshowList :: [GroupCallId] -> ShowS
showList :: [GroupCallId] -> ShowS
Show)

instance I.ShortShow GroupCallId where
  shortShow :: GroupCallId -> String
shortShow GroupCallId
    { _id :: GroupCallId -> Maybe Int
_id = Maybe Int
_id_
    }
      = String
"GroupCallId"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
        ]

instance AT.FromJSON GroupCallId where
  parseJSON :: Value -> Parser GroupCallId
parseJSON v :: Value
v@(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
"groupCallId" -> Value -> Parser GroupCallId
parseGroupCallId Value
v
      String
_             -> Parser GroupCallId
forall a. Monoid a => a
mempty
    
    where
      parseGroupCallId :: A.Value -> AT.Parser GroupCallId
      parseGroupCallId :: Value -> Parser GroupCallId
parseGroupCallId = String
-> (Object -> Parser GroupCallId) -> Value -> Parser GroupCallId
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GroupCallId" ((Object -> Parser GroupCallId) -> Value -> Parser GroupCallId)
-> (Object -> Parser GroupCallId) -> Value -> Parser GroupCallId
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"id"
        GroupCallId -> Parser GroupCallId
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GroupCallId -> Parser GroupCallId)
-> GroupCallId -> Parser GroupCallId
forall a b. (a -> b) -> a -> b
$ GroupCallId
          { _id :: Maybe Int
_id = Maybe Int
_id_
          }
  parseJSON Value
_ = Parser GroupCallId
forall a. Monoid a => a
mempty