module TD.Data.SearchMessagesChatTypeFilter
  (SearchMessagesChatTypeFilter(..)) where

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

-- | Represents a filter for type of the chats in which to search messages
data SearchMessagesChatTypeFilter
  = SearchMessagesChatTypeFilterPrivate -- ^ Returns only messages in private chats
  | SearchMessagesChatTypeFilterGroup -- ^ Returns only messages in basic group and supergroup chats
  | SearchMessagesChatTypeFilterChannel -- ^ Returns only messages in channel chats
  deriving (SearchMessagesChatTypeFilter
-> SearchMessagesChatTypeFilter -> Bool
(SearchMessagesChatTypeFilter
 -> SearchMessagesChatTypeFilter -> Bool)
-> (SearchMessagesChatTypeFilter
    -> SearchMessagesChatTypeFilter -> Bool)
-> Eq SearchMessagesChatTypeFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchMessagesChatTypeFilter
-> SearchMessagesChatTypeFilter -> Bool
== :: SearchMessagesChatTypeFilter
-> SearchMessagesChatTypeFilter -> Bool
$c/= :: SearchMessagesChatTypeFilter
-> SearchMessagesChatTypeFilter -> Bool
/= :: SearchMessagesChatTypeFilter
-> SearchMessagesChatTypeFilter -> Bool
Eq, Int -> SearchMessagesChatTypeFilter -> ShowS
[SearchMessagesChatTypeFilter] -> ShowS
SearchMessagesChatTypeFilter -> String
(Int -> SearchMessagesChatTypeFilter -> ShowS)
-> (SearchMessagesChatTypeFilter -> String)
-> ([SearchMessagesChatTypeFilter] -> ShowS)
-> Show SearchMessagesChatTypeFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchMessagesChatTypeFilter -> ShowS
showsPrec :: Int -> SearchMessagesChatTypeFilter -> ShowS
$cshow :: SearchMessagesChatTypeFilter -> String
show :: SearchMessagesChatTypeFilter -> String
$cshowList :: [SearchMessagesChatTypeFilter] -> ShowS
showList :: [SearchMessagesChatTypeFilter] -> ShowS
Show)

instance I.ShortShow SearchMessagesChatTypeFilter where
  shortShow :: SearchMessagesChatTypeFilter -> String
shortShow SearchMessagesChatTypeFilter
SearchMessagesChatTypeFilterPrivate
      = String
"SearchMessagesChatTypeFilterPrivate"
  shortShow SearchMessagesChatTypeFilter
SearchMessagesChatTypeFilterGroup
      = String
"SearchMessagesChatTypeFilterGroup"
  shortShow SearchMessagesChatTypeFilter
SearchMessagesChatTypeFilterChannel
      = String
"SearchMessagesChatTypeFilterChannel"

instance AT.FromJSON SearchMessagesChatTypeFilter where
  parseJSON :: Value -> Parser SearchMessagesChatTypeFilter
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
"searchMessagesChatTypeFilterPrivate" -> SearchMessagesChatTypeFilter -> Parser SearchMessagesChatTypeFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SearchMessagesChatTypeFilter
SearchMessagesChatTypeFilterPrivate
      String
"searchMessagesChatTypeFilterGroup"   -> SearchMessagesChatTypeFilter -> Parser SearchMessagesChatTypeFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SearchMessagesChatTypeFilter
SearchMessagesChatTypeFilterGroup
      String
"searchMessagesChatTypeFilterChannel" -> SearchMessagesChatTypeFilter -> Parser SearchMessagesChatTypeFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SearchMessagesChatTypeFilter
SearchMessagesChatTypeFilterChannel
      String
_                                     -> Parser SearchMessagesChatTypeFilter
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser SearchMessagesChatTypeFilter
forall a. Monoid a => a
mempty

instance AT.ToJSON SearchMessagesChatTypeFilter where
  toJSON :: SearchMessagesChatTypeFilter -> Value
toJSON SearchMessagesChatTypeFilter
SearchMessagesChatTypeFilterPrivate
      = [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
"searchMessagesChatTypeFilterPrivate"
        ]
  toJSON SearchMessagesChatTypeFilter
SearchMessagesChatTypeFilterGroup
      = [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
"searchMessagesChatTypeFilterGroup"
        ]
  toJSON SearchMessagesChatTypeFilter
SearchMessagesChatTypeFilterChannel
      = [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
"searchMessagesChatTypeFilterChannel"
        ]