module TD.Data.UserPrivacySettingRule
  (UserPrivacySettingRule(..)) where

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

-- | Represents a single rule for managing user privacy settings
data UserPrivacySettingRule
  = UserPrivacySettingRuleAllowAll -- ^ A rule to allow all users to do something
  | UserPrivacySettingRuleAllowContacts -- ^ A rule to allow all contacts of the user to do something
  | UserPrivacySettingRuleAllowPremiumUsers -- ^ A rule to allow all Premium Users to do something; currently, allowed only for userPrivacySettingAllowChatInvites
  | UserPrivacySettingRuleAllowUsers -- ^ A rule to allow certain specified users to do something
    { UserPrivacySettingRule -> Maybe [Int]
user_ids :: Maybe [Int] -- ^ The user identifiers, total number of users in all rules must not exceed 1000
    }
  | UserPrivacySettingRuleAllowChatMembers -- ^ A rule to allow all members of certain specified basic groups and supergroups to doing something
    { UserPrivacySettingRule -> Maybe [Int]
chat_ids :: Maybe [Int] -- ^ The chat identifiers, total number of chats in all rules must not exceed 20
    }
  | UserPrivacySettingRuleRestrictAll -- ^ A rule to restrict all users from doing something
  | UserPrivacySettingRuleRestrictContacts -- ^ A rule to restrict all contacts of the user from doing something
  | UserPrivacySettingRuleRestrictUsers -- ^ A rule to restrict all specified users from doing something
    { user_ids :: Maybe [Int] -- ^ The user identifiers, total number of users in all rules must not exceed 1000
    }
  | UserPrivacySettingRuleRestrictChatMembers -- ^ A rule to restrict all members of specified basic groups and supergroups from doing something
    { chat_ids :: Maybe [Int] -- ^ The chat identifiers, total number of chats in all rules must not exceed 20
    }
  deriving (UserPrivacySettingRule -> UserPrivacySettingRule -> Bool
(UserPrivacySettingRule -> UserPrivacySettingRule -> Bool)
-> (UserPrivacySettingRule -> UserPrivacySettingRule -> Bool)
-> Eq UserPrivacySettingRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserPrivacySettingRule -> UserPrivacySettingRule -> Bool
== :: UserPrivacySettingRule -> UserPrivacySettingRule -> Bool
$c/= :: UserPrivacySettingRule -> UserPrivacySettingRule -> Bool
/= :: UserPrivacySettingRule -> UserPrivacySettingRule -> Bool
Eq, Int -> UserPrivacySettingRule -> ShowS
[UserPrivacySettingRule] -> ShowS
UserPrivacySettingRule -> String
(Int -> UserPrivacySettingRule -> ShowS)
-> (UserPrivacySettingRule -> String)
-> ([UserPrivacySettingRule] -> ShowS)
-> Show UserPrivacySettingRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserPrivacySettingRule -> ShowS
showsPrec :: Int -> UserPrivacySettingRule -> ShowS
$cshow :: UserPrivacySettingRule -> String
show :: UserPrivacySettingRule -> String
$cshowList :: [UserPrivacySettingRule] -> ShowS
showList :: [UserPrivacySettingRule] -> ShowS
Show)

instance I.ShortShow UserPrivacySettingRule where
  shortShow :: UserPrivacySettingRule -> String
shortShow UserPrivacySettingRule
UserPrivacySettingRuleAllowAll
      = String
"UserPrivacySettingRuleAllowAll"
  shortShow UserPrivacySettingRule
UserPrivacySettingRuleAllowContacts
      = String
"UserPrivacySettingRuleAllowContacts"
  shortShow UserPrivacySettingRule
UserPrivacySettingRuleAllowPremiumUsers
      = String
"UserPrivacySettingRuleAllowPremiumUsers"
  shortShow UserPrivacySettingRuleAllowUsers
    { user_ids :: UserPrivacySettingRule -> Maybe [Int]
user_ids = Maybe [Int]
user_ids_
    }
      = String
"UserPrivacySettingRuleAllowUsers"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"user_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
user_ids_
        ]
  shortShow UserPrivacySettingRuleAllowChatMembers
    { chat_ids :: UserPrivacySettingRule -> Maybe [Int]
chat_ids = Maybe [Int]
chat_ids_
    }
      = String
"UserPrivacySettingRuleAllowChatMembers"
        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_
        ]
  shortShow UserPrivacySettingRule
UserPrivacySettingRuleRestrictAll
      = String
"UserPrivacySettingRuleRestrictAll"
  shortShow UserPrivacySettingRule
UserPrivacySettingRuleRestrictContacts
      = String
"UserPrivacySettingRuleRestrictContacts"
  shortShow UserPrivacySettingRuleRestrictUsers
    { user_ids :: UserPrivacySettingRule -> Maybe [Int]
user_ids = Maybe [Int]
user_ids_
    }
      = String
"UserPrivacySettingRuleRestrictUsers"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"user_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
user_ids_
        ]
  shortShow UserPrivacySettingRuleRestrictChatMembers
    { chat_ids :: UserPrivacySettingRule -> Maybe [Int]
chat_ids = Maybe [Int]
chat_ids_
    }
      = String
"UserPrivacySettingRuleRestrictChatMembers"
        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_
        ]

instance AT.FromJSON UserPrivacySettingRule where
  parseJSON :: Value -> Parser UserPrivacySettingRule
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
"userPrivacySettingRuleAllowAll"            -> UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserPrivacySettingRule
UserPrivacySettingRuleAllowAll
      String
"userPrivacySettingRuleAllowContacts"       -> UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserPrivacySettingRule
UserPrivacySettingRuleAllowContacts
      String
"userPrivacySettingRuleAllowPremiumUsers"   -> UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserPrivacySettingRule
UserPrivacySettingRuleAllowPremiumUsers
      String
"userPrivacySettingRuleAllowUsers"          -> Value -> Parser UserPrivacySettingRule
parseUserPrivacySettingRuleAllowUsers Value
v
      String
"userPrivacySettingRuleAllowChatMembers"    -> Value -> Parser UserPrivacySettingRule
parseUserPrivacySettingRuleAllowChatMembers Value
v
      String
"userPrivacySettingRuleRestrictAll"         -> UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserPrivacySettingRule
UserPrivacySettingRuleRestrictAll
      String
"userPrivacySettingRuleRestrictContacts"    -> UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserPrivacySettingRule
UserPrivacySettingRuleRestrictContacts
      String
"userPrivacySettingRuleRestrictUsers"       -> Value -> Parser UserPrivacySettingRule
parseUserPrivacySettingRuleRestrictUsers Value
v
      String
"userPrivacySettingRuleRestrictChatMembers" -> Value -> Parser UserPrivacySettingRule
parseUserPrivacySettingRuleRestrictChatMembers Value
v
      String
_                                           -> Parser UserPrivacySettingRule
forall a. Monoid a => a
mempty
    
    where
      parseUserPrivacySettingRuleAllowUsers :: A.Value -> AT.Parser UserPrivacySettingRule
      parseUserPrivacySettingRuleAllowUsers :: Value -> Parser UserPrivacySettingRule
parseUserPrivacySettingRuleAllowUsers = String
-> (Object -> Parser UserPrivacySettingRule)
-> Value
-> Parser UserPrivacySettingRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserPrivacySettingRuleAllowUsers" ((Object -> Parser UserPrivacySettingRule)
 -> Value -> Parser UserPrivacySettingRule)
-> (Object -> Parser UserPrivacySettingRule)
-> Value
-> Parser UserPrivacySettingRule
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [Int]
user_ids_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"user_ids"
        UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserPrivacySettingRule -> Parser UserPrivacySettingRule)
-> UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a b. (a -> b) -> a -> b
$ UserPrivacySettingRuleAllowUsers
          { user_ids :: Maybe [Int]
user_ids = Maybe [Int]
user_ids_
          }
      parseUserPrivacySettingRuleAllowChatMembers :: A.Value -> AT.Parser UserPrivacySettingRule
      parseUserPrivacySettingRuleAllowChatMembers :: Value -> Parser UserPrivacySettingRule
parseUserPrivacySettingRuleAllowChatMembers = String
-> (Object -> Parser UserPrivacySettingRule)
-> Value
-> Parser UserPrivacySettingRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserPrivacySettingRuleAllowChatMembers" ((Object -> Parser UserPrivacySettingRule)
 -> Value -> Parser UserPrivacySettingRule)
-> (Object -> Parser UserPrivacySettingRule)
-> Value
-> Parser UserPrivacySettingRule
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"
        UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserPrivacySettingRule -> Parser UserPrivacySettingRule)
-> UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a b. (a -> b) -> a -> b
$ UserPrivacySettingRuleAllowChatMembers
          { chat_ids :: Maybe [Int]
chat_ids = Maybe [Int]
chat_ids_
          }
      parseUserPrivacySettingRuleRestrictUsers :: A.Value -> AT.Parser UserPrivacySettingRule
      parseUserPrivacySettingRuleRestrictUsers :: Value -> Parser UserPrivacySettingRule
parseUserPrivacySettingRuleRestrictUsers = String
-> (Object -> Parser UserPrivacySettingRule)
-> Value
-> Parser UserPrivacySettingRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserPrivacySettingRuleRestrictUsers" ((Object -> Parser UserPrivacySettingRule)
 -> Value -> Parser UserPrivacySettingRule)
-> (Object -> Parser UserPrivacySettingRule)
-> Value
-> Parser UserPrivacySettingRule
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [Int]
user_ids_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"user_ids"
        UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserPrivacySettingRule -> Parser UserPrivacySettingRule)
-> UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a b. (a -> b) -> a -> b
$ UserPrivacySettingRuleRestrictUsers
          { user_ids :: Maybe [Int]
user_ids = Maybe [Int]
user_ids_
          }
      parseUserPrivacySettingRuleRestrictChatMembers :: A.Value -> AT.Parser UserPrivacySettingRule
      parseUserPrivacySettingRuleRestrictChatMembers :: Value -> Parser UserPrivacySettingRule
parseUserPrivacySettingRuleRestrictChatMembers = String
-> (Object -> Parser UserPrivacySettingRule)
-> Value
-> Parser UserPrivacySettingRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserPrivacySettingRuleRestrictChatMembers" ((Object -> Parser UserPrivacySettingRule)
 -> Value -> Parser UserPrivacySettingRule)
-> (Object -> Parser UserPrivacySettingRule)
-> Value
-> Parser UserPrivacySettingRule
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"
        UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserPrivacySettingRule -> Parser UserPrivacySettingRule)
-> UserPrivacySettingRule -> Parser UserPrivacySettingRule
forall a b. (a -> b) -> a -> b
$ UserPrivacySettingRuleRestrictChatMembers
          { chat_ids :: Maybe [Int]
chat_ids = Maybe [Int]
chat_ids_
          }
  parseJSON Value
_ = Parser UserPrivacySettingRule
forall a. Monoid a => a
mempty

instance AT.ToJSON UserPrivacySettingRule where
  toJSON :: UserPrivacySettingRule -> Value
toJSON UserPrivacySettingRule
UserPrivacySettingRuleAllowAll
      = [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
"userPrivacySettingRuleAllowAll"
        ]
  toJSON UserPrivacySettingRule
UserPrivacySettingRuleAllowContacts
      = [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
"userPrivacySettingRuleAllowContacts"
        ]
  toJSON UserPrivacySettingRule
UserPrivacySettingRuleAllowPremiumUsers
      = [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
"userPrivacySettingRuleAllowPremiumUsers"
        ]
  toJSON UserPrivacySettingRuleAllowUsers
    { user_ids :: UserPrivacySettingRule -> Maybe [Int]
user_ids = Maybe [Int]
user_ids_
    }
      = [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
"userPrivacySettingRuleAllowUsers"
        , Key
"user_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]
user_ids_
        ]
  toJSON UserPrivacySettingRuleAllowChatMembers
    { chat_ids :: UserPrivacySettingRule -> Maybe [Int]
chat_ids = Maybe [Int]
chat_ids_
    }
      = [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
"userPrivacySettingRuleAllowChatMembers"
        , 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_
        ]
  toJSON UserPrivacySettingRule
UserPrivacySettingRuleRestrictAll
      = [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
"userPrivacySettingRuleRestrictAll"
        ]
  toJSON UserPrivacySettingRule
UserPrivacySettingRuleRestrictContacts
      = [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
"userPrivacySettingRuleRestrictContacts"
        ]
  toJSON UserPrivacySettingRuleRestrictUsers
    { user_ids :: UserPrivacySettingRule -> Maybe [Int]
user_ids = Maybe [Int]
user_ids_
    }
      = [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
"userPrivacySettingRuleRestrictUsers"
        , Key
"user_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]
user_ids_
        ]
  toJSON UserPrivacySettingRuleRestrictChatMembers
    { chat_ids :: UserPrivacySettingRule -> Maybe [Int]
chat_ids = Maybe [Int]
chat_ids_
    }
      = [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
"userPrivacySettingRuleRestrictChatMembers"
        , 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_
        ]