module TD.Data.InputPhoto
  ( InputPhoto(..)    
  , defaultInputPhoto 
  ) where

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

data InputPhoto
  = InputPhoto -- ^ A photo to be sent
    { InputPhoto -> Maybe InputFile
photo                  :: Maybe InputFile.InputFile           -- ^ Photo to be sent. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20
    , InputPhoto -> Maybe InputThumbnail
thumbnail              :: Maybe InputThumbnail.InputThumbnail -- ^ Photo thumbnail; pass null to skip thumbnail uploading. The thumbnail is sent to the other party only in secret chats
    , InputPhoto -> Maybe InputFile
video                  :: Maybe InputFile.InputFile           -- ^ Video of the live photo; not supported in secret chats; pass null if the photo isn't a live photo
    , InputPhoto -> Maybe [Int]
added_sticker_file_ids :: Maybe [Int]                         -- ^ File identifiers of the stickers added to the photo, if applicable
    , InputPhoto -> Maybe Int
width                  :: Maybe Int                           -- ^ Photo width; may be replaced by the server
    , InputPhoto -> Maybe Int
height                 :: Maybe Int                           -- ^ Photo height; may be replaced by the server
    }
  deriving (InputPhoto -> InputPhoto -> Bool
(InputPhoto -> InputPhoto -> Bool)
-> (InputPhoto -> InputPhoto -> Bool) -> Eq InputPhoto
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputPhoto -> InputPhoto -> Bool
== :: InputPhoto -> InputPhoto -> Bool
$c/= :: InputPhoto -> InputPhoto -> Bool
/= :: InputPhoto -> InputPhoto -> Bool
Eq, Int -> InputPhoto -> ShowS
[InputPhoto] -> ShowS
InputPhoto -> String
(Int -> InputPhoto -> ShowS)
-> (InputPhoto -> String)
-> ([InputPhoto] -> ShowS)
-> Show InputPhoto
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputPhoto -> ShowS
showsPrec :: Int -> InputPhoto -> ShowS
$cshow :: InputPhoto -> String
show :: InputPhoto -> String
$cshowList :: [InputPhoto] -> ShowS
showList :: [InputPhoto] -> ShowS
Show)

instance I.ShortShow InputPhoto where
  shortShow :: InputPhoto -> String
shortShow InputPhoto
    { photo :: InputPhoto -> Maybe InputFile
photo                  = Maybe InputFile
photo_
    , thumbnail :: InputPhoto -> Maybe InputThumbnail
thumbnail              = Maybe InputThumbnail
thumbnail_
    , video :: InputPhoto -> Maybe InputFile
video                  = Maybe InputFile
video_
    , added_sticker_file_ids :: InputPhoto -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
    , width :: InputPhoto -> Maybe Int
width                  = Maybe Int
width_
    , height :: InputPhoto -> Maybe Int
height                 = Maybe Int
height_
    }
      = String
"InputPhoto"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"photo"                  String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
photo_
        , String
"thumbnail"              String -> Maybe InputThumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputThumbnail
thumbnail_
        , String
"video"                  String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
video_
        , String
"added_sticker_file_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
added_sticker_file_ids_
        , 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_
        ]

instance AT.FromJSON InputPhoto where
  parseJSON :: Value -> Parser InputPhoto
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
"inputPhoto" -> Value -> Parser InputPhoto
parseInputPhoto Value
v
      String
_            -> Parser InputPhoto
forall a. Monoid a => a
mempty
    
    where
      parseInputPhoto :: A.Value -> AT.Parser InputPhoto
      parseInputPhoto :: Value -> Parser InputPhoto
parseInputPhoto = String
-> (Object -> Parser InputPhoto) -> Value -> Parser InputPhoto
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputPhoto" ((Object -> Parser InputPhoto) -> Value -> Parser InputPhoto)
-> (Object -> Parser InputPhoto) -> Value -> Parser InputPhoto
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe InputFile
photo_                  <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"photo"
        Maybe InputThumbnail
thumbnail_              <- Object
o Object -> Key -> Parser (Maybe InputThumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"thumbnail"
        Maybe InputFile
video_                  <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"video"
        Maybe [Int]
added_sticker_file_ids_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"added_sticker_file_ids"
        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"
        InputPhoto -> Parser InputPhoto
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputPhoto -> Parser InputPhoto)
-> InputPhoto -> Parser InputPhoto
forall a b. (a -> b) -> a -> b
$ InputPhoto
          { photo :: Maybe InputFile
photo                  = Maybe InputFile
photo_
          , thumbnail :: Maybe InputThumbnail
thumbnail              = Maybe InputThumbnail
thumbnail_
          , video :: Maybe InputFile
video                  = Maybe InputFile
video_
          , added_sticker_file_ids :: Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
          , width :: Maybe Int
width                  = Maybe Int
width_
          , height :: Maybe Int
height                 = Maybe Int
height_
          }
  parseJSON Value
_ = Parser InputPhoto
forall a. Monoid a => a
mempty

instance AT.ToJSON InputPhoto where
  toJSON :: InputPhoto -> Value
toJSON InputPhoto
    { photo :: InputPhoto -> Maybe InputFile
photo                  = Maybe InputFile
photo_
    , thumbnail :: InputPhoto -> Maybe InputThumbnail
thumbnail              = Maybe InputThumbnail
thumbnail_
    , video :: InputPhoto -> Maybe InputFile
video                  = Maybe InputFile
video_
    , added_sticker_file_ids :: InputPhoto -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
    , width :: InputPhoto -> Maybe Int
width                  = Maybe Int
width_
    , height :: InputPhoto -> Maybe Int
height                 = Maybe Int
height_
    }
      = [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
"inputPhoto"
        , Key
"photo"                  Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
photo_
        , Key
"thumbnail"              Key -> Maybe InputThumbnail -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputThumbnail
thumbnail_
        , Key
"video"                  Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
video_
        , Key
"added_sticker_file_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]
added_sticker_file_ids_
        , Key
"width"                  Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
width_
        , Key
"height"                 Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
height_
        ]

defaultInputPhoto :: InputPhoto
defaultInputPhoto :: InputPhoto
defaultInputPhoto =
  InputPhoto
    { photo :: Maybe InputFile
photo                  = Maybe InputFile
forall a. Maybe a
Nothing
    , thumbnail :: Maybe InputThumbnail
thumbnail              = Maybe InputThumbnail
forall a. Maybe a
Nothing
    , video :: Maybe InputFile
video                  = Maybe InputFile
forall a. Maybe a
Nothing
    , added_sticker_file_ids :: Maybe [Int]
added_sticker_file_ids = Maybe [Int]
forall a. Maybe a
Nothing
    , width :: Maybe Int
width                  = Maybe Int
forall a. Maybe a
Nothing
    , height :: Maybe Int
height                 = Maybe Int
forall a. Maybe a
Nothing
    }