module TD.Data.SearchChatTypeFilter
  (SearchChatTypeFilter(..)) 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 to search for
data SearchChatTypeFilter
  = SearchChatTypeFilterBot -- ^ Returns only private chats with bots
  | SearchChatTypeFilterChannel -- ^ Returns only channel chats
  deriving (SearchChatTypeFilter -> SearchChatTypeFilter -> Bool
(SearchChatTypeFilter -> SearchChatTypeFilter -> Bool)
-> (SearchChatTypeFilter -> SearchChatTypeFilter -> Bool)
-> Eq SearchChatTypeFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchChatTypeFilter -> SearchChatTypeFilter -> Bool
== :: SearchChatTypeFilter -> SearchChatTypeFilter -> Bool
$c/= :: SearchChatTypeFilter -> SearchChatTypeFilter -> Bool
/= :: SearchChatTypeFilter -> SearchChatTypeFilter -> Bool
Eq, Int -> SearchChatTypeFilter -> ShowS
[SearchChatTypeFilter] -> ShowS
SearchChatTypeFilter -> String
(Int -> SearchChatTypeFilter -> ShowS)
-> (SearchChatTypeFilter -> String)
-> ([SearchChatTypeFilter] -> ShowS)
-> Show SearchChatTypeFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchChatTypeFilter -> ShowS
showsPrec :: Int -> SearchChatTypeFilter -> ShowS
$cshow :: SearchChatTypeFilter -> String
show :: SearchChatTypeFilter -> String
$cshowList :: [SearchChatTypeFilter] -> ShowS
showList :: [SearchChatTypeFilter] -> ShowS
Show)

instance I.ShortShow SearchChatTypeFilter where
  shortShow :: SearchChatTypeFilter -> String
shortShow SearchChatTypeFilter
SearchChatTypeFilterBot
      = String
"SearchChatTypeFilterBot"
  shortShow SearchChatTypeFilter
SearchChatTypeFilterChannel
      = String
"SearchChatTypeFilterChannel"

instance AT.FromJSON SearchChatTypeFilter where
  parseJSON :: Value -> Parser SearchChatTypeFilter
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
"searchChatTypeFilterBot"     -> SearchChatTypeFilter -> Parser SearchChatTypeFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SearchChatTypeFilter
SearchChatTypeFilterBot
      String
"searchChatTypeFilterChannel" -> SearchChatTypeFilter -> Parser SearchChatTypeFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SearchChatTypeFilter
SearchChatTypeFilterChannel
      String
_                             -> Parser SearchChatTypeFilter
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser SearchChatTypeFilter
forall a. Monoid a => a
mempty

instance AT.ToJSON SearchChatTypeFilter where
  toJSON :: SearchChatTypeFilter -> Value
toJSON SearchChatTypeFilter
SearchChatTypeFilterBot
      = [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
"searchChatTypeFilterBot"
        ]
  toJSON SearchChatTypeFilter
SearchChatTypeFilterChannel
      = [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
"searchChatTypeFilterChannel"
        ]