module TD.Data.GiveawayParameters
( GiveawayParameters(..)
, defaultGiveawayParameters
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
data GiveawayParameters
= GiveawayParameters
{ GiveawayParameters -> Maybe Int
boosted_chat_id :: Maybe Int
, GiveawayParameters -> Maybe [Int]
additional_chat_ids :: Maybe [Int]
, GiveawayParameters -> Maybe Int
winners_selection_date :: Maybe Int
, GiveawayParameters -> Maybe Bool
only_new_members :: Maybe Bool
, GiveawayParameters -> Maybe Bool
has_public_winners :: Maybe Bool
, GiveawayParameters -> Maybe [Text]
country_codes :: Maybe [T.Text]
, GiveawayParameters -> Maybe Text
prize_description :: Maybe T.Text
}
deriving (GiveawayParameters -> GiveawayParameters -> Bool
(GiveawayParameters -> GiveawayParameters -> Bool)
-> (GiveawayParameters -> GiveawayParameters -> Bool)
-> Eq GiveawayParameters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiveawayParameters -> GiveawayParameters -> Bool
== :: GiveawayParameters -> GiveawayParameters -> Bool
$c/= :: GiveawayParameters -> GiveawayParameters -> Bool
/= :: GiveawayParameters -> GiveawayParameters -> Bool
Eq, Int -> GiveawayParameters -> ShowS
[GiveawayParameters] -> ShowS
GiveawayParameters -> String
(Int -> GiveawayParameters -> ShowS)
-> (GiveawayParameters -> String)
-> ([GiveawayParameters] -> ShowS)
-> Show GiveawayParameters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiveawayParameters -> ShowS
showsPrec :: Int -> GiveawayParameters -> ShowS
$cshow :: GiveawayParameters -> String
show :: GiveawayParameters -> String
$cshowList :: [GiveawayParameters] -> ShowS
showList :: [GiveawayParameters] -> ShowS
Show)
instance I.ShortShow GiveawayParameters where
shortShow :: GiveawayParameters -> String
shortShow GiveawayParameters
{ boosted_chat_id :: GiveawayParameters -> Maybe Int
boosted_chat_id = Maybe Int
boosted_chat_id_
, additional_chat_ids :: GiveawayParameters -> Maybe [Int]
additional_chat_ids = Maybe [Int]
additional_chat_ids_
, winners_selection_date :: GiveawayParameters -> Maybe Int
winners_selection_date = Maybe Int
winners_selection_date_
, only_new_members :: GiveawayParameters -> Maybe Bool
only_new_members = Maybe Bool
only_new_members_
, has_public_winners :: GiveawayParameters -> Maybe Bool
has_public_winners = Maybe Bool
has_public_winners_
, country_codes :: GiveawayParameters -> Maybe [Text]
country_codes = Maybe [Text]
country_codes_
, prize_description :: GiveawayParameters -> Maybe Text
prize_description = Maybe Text
prize_description_
}
= String
"GiveawayParameters"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"boosted_chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
boosted_chat_id_
, String
"additional_chat_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
additional_chat_ids_
, String
"winners_selection_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
winners_selection_date_
, String
"only_new_members" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
only_new_members_
, String
"has_public_winners" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_public_winners_
, String
"country_codes" String -> Maybe [Text] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Text]
country_codes_
, String
"prize_description" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
prize_description_
]
instance AT.FromJSON GiveawayParameters where
parseJSON :: Value -> Parser GiveawayParameters
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
"giveawayParameters" -> Value -> Parser GiveawayParameters
parseGiveawayParameters Value
v
String
_ -> Parser GiveawayParameters
forall a. Monoid a => a
mempty
where
parseGiveawayParameters :: A.Value -> AT.Parser GiveawayParameters
parseGiveawayParameters :: Value -> Parser GiveawayParameters
parseGiveawayParameters = String
-> (Object -> Parser GiveawayParameters)
-> Value
-> Parser GiveawayParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiveawayParameters" ((Object -> Parser GiveawayParameters)
-> Value -> Parser GiveawayParameters)
-> (Object -> Parser GiveawayParameters)
-> Value
-> Parser GiveawayParameters
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
boosted_chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"boosted_chat_id"
Maybe [Int]
additional_chat_ids_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"additional_chat_ids"
Maybe Int
winners_selection_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"winners_selection_date"
Maybe Bool
only_new_members_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"only_new_members"
Maybe Bool
has_public_winners_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"has_public_winners"
Maybe [Text]
country_codes_ <- Object
o Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"country_codes"
Maybe Text
prize_description_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"prize_description"
GiveawayParameters -> Parser GiveawayParameters
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiveawayParameters -> Parser GiveawayParameters)
-> GiveawayParameters -> Parser GiveawayParameters
forall a b. (a -> b) -> a -> b
$ GiveawayParameters
{ boosted_chat_id :: Maybe Int
boosted_chat_id = Maybe Int
boosted_chat_id_
, additional_chat_ids :: Maybe [Int]
additional_chat_ids = Maybe [Int]
additional_chat_ids_
, winners_selection_date :: Maybe Int
winners_selection_date = Maybe Int
winners_selection_date_
, only_new_members :: Maybe Bool
only_new_members = Maybe Bool
only_new_members_
, has_public_winners :: Maybe Bool
has_public_winners = Maybe Bool
has_public_winners_
, country_codes :: Maybe [Text]
country_codes = Maybe [Text]
country_codes_
, prize_description :: Maybe Text
prize_description = Maybe Text
prize_description_
}
parseJSON Value
_ = Parser GiveawayParameters
forall a. Monoid a => a
mempty
instance AT.ToJSON GiveawayParameters where
toJSON :: GiveawayParameters -> Value
toJSON GiveawayParameters
{ boosted_chat_id :: GiveawayParameters -> Maybe Int
boosted_chat_id = Maybe Int
boosted_chat_id_
, additional_chat_ids :: GiveawayParameters -> Maybe [Int]
additional_chat_ids = Maybe [Int]
additional_chat_ids_
, winners_selection_date :: GiveawayParameters -> Maybe Int
winners_selection_date = Maybe Int
winners_selection_date_
, only_new_members :: GiveawayParameters -> Maybe Bool
only_new_members = Maybe Bool
only_new_members_
, has_public_winners :: GiveawayParameters -> Maybe Bool
has_public_winners = Maybe Bool
has_public_winners_
, country_codes :: GiveawayParameters -> Maybe [Text]
country_codes = Maybe [Text]
country_codes_
, prize_description :: GiveawayParameters -> Maybe Text
prize_description = Maybe Text
prize_description_
}
= [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
"giveawayParameters"
, Key
"boosted_chat_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
boosted_chat_id_
, Key
"additional_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]
additional_chat_ids_
, Key
"winners_selection_date" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
winners_selection_date_
, Key
"only_new_members" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
only_new_members_
, Key
"has_public_winners" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
has_public_winners_
, Key
"country_codes" Key -> Maybe [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Text]
country_codes_
, Key
"prize_description" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
prize_description_
]
defaultGiveawayParameters :: GiveawayParameters
defaultGiveawayParameters :: GiveawayParameters
defaultGiveawayParameters =
GiveawayParameters
{ boosted_chat_id :: Maybe Int
boosted_chat_id = Maybe Int
forall a. Maybe a
Nothing
, additional_chat_ids :: Maybe [Int]
additional_chat_ids = Maybe [Int]
forall a. Maybe a
Nothing
, winners_selection_date :: Maybe Int
winners_selection_date = Maybe Int
forall a. Maybe a
Nothing
, only_new_members :: Maybe Bool
only_new_members = Maybe Bool
forall a. Maybe a
Nothing
, has_public_winners :: Maybe Bool
has_public_winners = Maybe Bool
forall a. Maybe a
Nothing
, country_codes :: Maybe [Text]
country_codes = Maybe [Text]
forall a. Maybe a
Nothing
, prize_description :: Maybe Text
prize_description = Maybe Text
forall a. Maybe a
Nothing
}