module TD.Data.PhotoSize
(PhotoSize(..)) 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
import qualified TD.Data.File as File
data PhotoSize
= PhotoSize
{ PhotoSize -> Maybe Text
_type :: Maybe T.Text
, PhotoSize -> Maybe File
photo :: Maybe File.File
, PhotoSize -> Maybe Int
width :: Maybe Int
, PhotoSize -> Maybe Int
height :: Maybe Int
, PhotoSize -> Maybe [Int]
progressive_sizes :: Maybe [Int]
}
deriving (PhotoSize -> PhotoSize -> Bool
(PhotoSize -> PhotoSize -> Bool)
-> (PhotoSize -> PhotoSize -> Bool) -> Eq PhotoSize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PhotoSize -> PhotoSize -> Bool
== :: PhotoSize -> PhotoSize -> Bool
$c/= :: PhotoSize -> PhotoSize -> Bool
/= :: PhotoSize -> PhotoSize -> Bool
Eq, Int -> PhotoSize -> ShowS
[PhotoSize] -> ShowS
PhotoSize -> String
(Int -> PhotoSize -> ShowS)
-> (PhotoSize -> String)
-> ([PhotoSize] -> ShowS)
-> Show PhotoSize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PhotoSize -> ShowS
showsPrec :: Int -> PhotoSize -> ShowS
$cshow :: PhotoSize -> String
show :: PhotoSize -> String
$cshowList :: [PhotoSize] -> ShowS
showList :: [PhotoSize] -> ShowS
Show)
instance I.ShortShow PhotoSize where
shortShow :: PhotoSize -> String
shortShow PhotoSize
{ _type :: PhotoSize -> Maybe Text
_type = Maybe Text
_type_
, photo :: PhotoSize -> Maybe File
photo = Maybe File
photo_
, width :: PhotoSize -> Maybe Int
width = Maybe Int
width_
, height :: PhotoSize -> Maybe Int
height = Maybe Int
height_
, progressive_sizes :: PhotoSize -> Maybe [Int]
progressive_sizes = Maybe [Int]
progressive_sizes_
}
= String
"PhotoSize"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_type" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_type_
, String
"photo" String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
photo_
, String
"width" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
width_
, String
"height" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
height_
, String
"progressive_sizes" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
progressive_sizes_
]
instance AT.FromJSON PhotoSize where
parseJSON :: Value -> Parser PhotoSize
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
"photoSize" -> Value -> Parser PhotoSize
parsePhotoSize Value
v
String
_ -> Parser PhotoSize
forall a. Monoid a => a
mempty
where
parsePhotoSize :: A.Value -> AT.Parser PhotoSize
parsePhotoSize :: Value -> Parser PhotoSize
parsePhotoSize = String -> (Object -> Parser PhotoSize) -> Value -> Parser PhotoSize
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PhotoSize" ((Object -> Parser PhotoSize) -> Value -> Parser PhotoSize)
-> (Object -> Parser PhotoSize) -> Value -> Parser PhotoSize
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
_type_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
Maybe File
photo_ <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"photo"
Maybe Int
width_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"width"
Maybe Int
height_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"height"
Maybe [Int]
progressive_sizes_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"progressive_sizes"
PhotoSize -> Parser PhotoSize
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PhotoSize -> Parser PhotoSize) -> PhotoSize -> Parser PhotoSize
forall a b. (a -> b) -> a -> b
$ PhotoSize
{ _type :: Maybe Text
_type = Maybe Text
_type_
, photo :: Maybe File
photo = Maybe File
photo_
, width :: Maybe Int
width = Maybe Int
width_
, height :: Maybe Int
height = Maybe Int
height_
, progressive_sizes :: Maybe [Int]
progressive_sizes = Maybe [Int]
progressive_sizes_
}
parseJSON Value
_ = Parser PhotoSize
forall a. Monoid a => a
mempty