module TD.Data.PublicChatType
  (PublicChatType(..)) where

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

-- | Describes type of public chat
data PublicChatType
  = PublicChatTypeHasUsername -- ^ The chat is public, because it has an active username
  | PublicChatTypeIsLocationBased -- ^ The chat is public, because it is a location-based supergroup
  deriving (PublicChatType -> PublicChatType -> Bool
(PublicChatType -> PublicChatType -> Bool)
-> (PublicChatType -> PublicChatType -> Bool) -> Eq PublicChatType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PublicChatType -> PublicChatType -> Bool
== :: PublicChatType -> PublicChatType -> Bool
$c/= :: PublicChatType -> PublicChatType -> Bool
/= :: PublicChatType -> PublicChatType -> Bool
Eq, Int -> PublicChatType -> ShowS
[PublicChatType] -> ShowS
PublicChatType -> String
(Int -> PublicChatType -> ShowS)
-> (PublicChatType -> String)
-> ([PublicChatType] -> ShowS)
-> Show PublicChatType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PublicChatType -> ShowS
showsPrec :: Int -> PublicChatType -> ShowS
$cshow :: PublicChatType -> String
show :: PublicChatType -> String
$cshowList :: [PublicChatType] -> ShowS
showList :: [PublicChatType] -> ShowS
Show)

instance I.ShortShow PublicChatType where
  shortShow :: PublicChatType -> String
shortShow PublicChatType
PublicChatTypeHasUsername
      = String
"PublicChatTypeHasUsername"
  shortShow PublicChatType
PublicChatTypeIsLocationBased
      = String
"PublicChatTypeIsLocationBased"

instance AT.FromJSON PublicChatType where
  parseJSON :: Value -> Parser PublicChatType
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
"publicChatTypeHasUsername"     -> PublicChatType -> Parser PublicChatType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PublicChatType
PublicChatTypeHasUsername
      String
"publicChatTypeIsLocationBased" -> PublicChatType -> Parser PublicChatType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PublicChatType
PublicChatTypeIsLocationBased
      String
_                               -> Parser PublicChatType
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser PublicChatType
forall a. Monoid a => a
mempty

instance AT.ToJSON PublicChatType where
  toJSON :: PublicChatType -> Value
toJSON PublicChatType
PublicChatTypeHasUsername
      = [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
"publicChatTypeHasUsername"
        ]
  toJSON PublicChatType
PublicChatTypeIsLocationBased
      = [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
"publicChatTypeIsLocationBased"
        ]