module TD.Data.BusinessRecipients
  ( BusinessRecipients(..)    
  , defaultBusinessRecipients 
  ) where

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

data BusinessRecipients
  = BusinessRecipients -- ^ Describes private chats chosen for automatic interaction with a business
    { BusinessRecipients -> Maybe [Int]
chat_ids              :: Maybe [Int] -- ^ Identifiers of selected private chats
    , BusinessRecipients -> Maybe [Int]
excluded_chat_ids     :: Maybe [Int] -- ^ Identifiers of private chats that are always excluded; for businessConnectedBot only
    , BusinessRecipients -> Maybe Bool
select_existing_chats :: Maybe Bool  -- ^ True, if all existing private chats are selected
    , BusinessRecipients -> Maybe Bool
select_new_chats      :: Maybe Bool  -- ^ True, if all new private chats are selected
    , BusinessRecipients -> Maybe Bool
select_contacts       :: Maybe Bool  -- ^ True, if all private chats with contacts are selected
    , BusinessRecipients -> Maybe Bool
select_non_contacts   :: Maybe Bool  -- ^ True, if all private chats with non-contacts are selected
    , BusinessRecipients -> Maybe Bool
exclude_selected      :: Maybe Bool  -- ^ If true, then all private chats except the selected are chosen. Otherwise, only the selected chats are chosen
    }
  deriving (BusinessRecipients -> BusinessRecipients -> Bool
(BusinessRecipients -> BusinessRecipients -> Bool)
-> (BusinessRecipients -> BusinessRecipients -> Bool)
-> Eq BusinessRecipients
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BusinessRecipients -> BusinessRecipients -> Bool
== :: BusinessRecipients -> BusinessRecipients -> Bool
$c/= :: BusinessRecipients -> BusinessRecipients -> Bool
/= :: BusinessRecipients -> BusinessRecipients -> Bool
Eq, Int -> BusinessRecipients -> ShowS
[BusinessRecipients] -> ShowS
BusinessRecipients -> String
(Int -> BusinessRecipients -> ShowS)
-> (BusinessRecipients -> String)
-> ([BusinessRecipients] -> ShowS)
-> Show BusinessRecipients
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BusinessRecipients -> ShowS
showsPrec :: Int -> BusinessRecipients -> ShowS
$cshow :: BusinessRecipients -> String
show :: BusinessRecipients -> String
$cshowList :: [BusinessRecipients] -> ShowS
showList :: [BusinessRecipients] -> ShowS
Show)

instance I.ShortShow BusinessRecipients where
  shortShow :: BusinessRecipients -> String
shortShow BusinessRecipients
    { chat_ids :: BusinessRecipients -> Maybe [Int]
chat_ids              = Maybe [Int]
chat_ids_
    , excluded_chat_ids :: BusinessRecipients -> Maybe [Int]
excluded_chat_ids     = Maybe [Int]
excluded_chat_ids_
    , select_existing_chats :: BusinessRecipients -> Maybe Bool
select_existing_chats = Maybe Bool
select_existing_chats_
    , select_new_chats :: BusinessRecipients -> Maybe Bool
select_new_chats      = Maybe Bool
select_new_chats_
    , select_contacts :: BusinessRecipients -> Maybe Bool
select_contacts       = Maybe Bool
select_contacts_
    , select_non_contacts :: BusinessRecipients -> Maybe Bool
select_non_contacts   = Maybe Bool
select_non_contacts_
    , exclude_selected :: BusinessRecipients -> Maybe Bool
exclude_selected      = Maybe Bool
exclude_selected_
    }
      = String
"BusinessRecipients"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"chat_ids"              String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
chat_ids_
        , String
"excluded_chat_ids"     String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
excluded_chat_ids_
        , String
"select_existing_chats" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
select_existing_chats_
        , String
"select_new_chats"      String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
select_new_chats_
        , String
"select_contacts"       String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
select_contacts_
        , String
"select_non_contacts"   String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
select_non_contacts_
        , String
"exclude_selected"      String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
exclude_selected_
        ]

instance AT.FromJSON BusinessRecipients where
  parseJSON :: Value -> Parser BusinessRecipients
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
"businessRecipients" -> Value -> Parser BusinessRecipients
parseBusinessRecipients Value
v
      String
_                    -> Parser BusinessRecipients
forall a. Monoid a => a
mempty
    
    where
      parseBusinessRecipients :: A.Value -> AT.Parser BusinessRecipients
      parseBusinessRecipients :: Value -> Parser BusinessRecipients
parseBusinessRecipients = String
-> (Object -> Parser BusinessRecipients)
-> Value
-> Parser BusinessRecipients
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BusinessRecipients" ((Object -> Parser BusinessRecipients)
 -> Value -> Parser BusinessRecipients)
-> (Object -> Parser BusinessRecipients)
-> Value
-> Parser BusinessRecipients
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [Int]
chat_ids_              <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chat_ids"
        Maybe [Int]
excluded_chat_ids_     <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"excluded_chat_ids"
        Maybe Bool
select_existing_chats_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"select_existing_chats"
        Maybe Bool
select_new_chats_      <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"select_new_chats"
        Maybe Bool
select_contacts_       <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"select_contacts"
        Maybe Bool
select_non_contacts_   <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"select_non_contacts"
        Maybe Bool
exclude_selected_      <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"exclude_selected"
        BusinessRecipients -> Parser BusinessRecipients
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BusinessRecipients -> Parser BusinessRecipients)
-> BusinessRecipients -> Parser BusinessRecipients
forall a b. (a -> b) -> a -> b
$ BusinessRecipients
          { chat_ids :: Maybe [Int]
chat_ids              = Maybe [Int]
chat_ids_
          , excluded_chat_ids :: Maybe [Int]
excluded_chat_ids     = Maybe [Int]
excluded_chat_ids_
          , select_existing_chats :: Maybe Bool
select_existing_chats = Maybe Bool
select_existing_chats_
          , select_new_chats :: Maybe Bool
select_new_chats      = Maybe Bool
select_new_chats_
          , select_contacts :: Maybe Bool
select_contacts       = Maybe Bool
select_contacts_
          , select_non_contacts :: Maybe Bool
select_non_contacts   = Maybe Bool
select_non_contacts_
          , exclude_selected :: Maybe Bool
exclude_selected      = Maybe Bool
exclude_selected_
          }
  parseJSON Value
_ = Parser BusinessRecipients
forall a. Monoid a => a
mempty

instance AT.ToJSON BusinessRecipients where
  toJSON :: BusinessRecipients -> Value
toJSON BusinessRecipients
    { chat_ids :: BusinessRecipients -> Maybe [Int]
chat_ids              = Maybe [Int]
chat_ids_
    , excluded_chat_ids :: BusinessRecipients -> Maybe [Int]
excluded_chat_ids     = Maybe [Int]
excluded_chat_ids_
    , select_existing_chats :: BusinessRecipients -> Maybe Bool
select_existing_chats = Maybe Bool
select_existing_chats_
    , select_new_chats :: BusinessRecipients -> Maybe Bool
select_new_chats      = Maybe Bool
select_new_chats_
    , select_contacts :: BusinessRecipients -> Maybe Bool
select_contacts       = Maybe Bool
select_contacts_
    , select_non_contacts :: BusinessRecipients -> Maybe Bool
select_non_contacts   = Maybe Bool
select_non_contacts_
    , exclude_selected :: BusinessRecipients -> Maybe Bool
exclude_selected      = Maybe Bool
exclude_selected_
    }
      = [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
"businessRecipients"
        , Key
"chat_ids"              Key -> Maybe [Int] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Int]
chat_ids_
        , Key
"excluded_chat_ids"     Key -> Maybe [Int] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Int]
excluded_chat_ids_
        , Key
"select_existing_chats" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
select_existing_chats_
        , Key
"select_new_chats"      Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
select_new_chats_
        , Key
"select_contacts"       Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
select_contacts_
        , Key
"select_non_contacts"   Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
select_non_contacts_
        , Key
"exclude_selected"      Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
exclude_selected_
        ]

defaultBusinessRecipients :: BusinessRecipients
defaultBusinessRecipients :: BusinessRecipients
defaultBusinessRecipients =
  BusinessRecipients
    { chat_ids :: Maybe [Int]
chat_ids              = Maybe [Int]
forall a. Maybe a
Nothing
    , excluded_chat_ids :: Maybe [Int]
excluded_chat_ids     = Maybe [Int]
forall a. Maybe a
Nothing
    , select_existing_chats :: Maybe Bool
select_existing_chats = Maybe Bool
forall a. Maybe a
Nothing
    , select_new_chats :: Maybe Bool
select_new_chats      = Maybe Bool
forall a. Maybe a
Nothing
    , select_contacts :: Maybe Bool
select_contacts       = Maybe Bool
forall a. Maybe a
Nothing
    , select_non_contacts :: Maybe Bool
select_non_contacts   = Maybe Bool
forall a. Maybe a
Nothing
    , exclude_selected :: Maybe Bool
exclude_selected      = Maybe Bool
forall a. Maybe a
Nothing
    }