module TD.Data.InputThumbnail
  ( InputThumbnail(..)    
  , defaultInputThumbnail 
  ) 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

data InputThumbnail
  = InputThumbnail -- ^ A thumbnail to be sent along with a file; must be in JPEG or WEBP format for stickers, and less than 200 KB in size
    { InputThumbnail -> Maybe InputFile
thumbnail :: Maybe InputFile.InputFile -- ^ Thumbnail file to send. Sending thumbnails by file_id is currently not supported
    , InputThumbnail -> Maybe Int
width     :: Maybe Int                 -- ^ Thumbnail width, usually shouldn't exceed 320. Use 0 if unknown
    , InputThumbnail -> Maybe Int
height    :: Maybe Int                 -- ^ Thumbnail height, usually shouldn't exceed 320. Use 0 if unknown
    }
  deriving (InputThumbnail -> InputThumbnail -> Bool
(InputThumbnail -> InputThumbnail -> Bool)
-> (InputThumbnail -> InputThumbnail -> Bool) -> Eq InputThumbnail
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputThumbnail -> InputThumbnail -> Bool
== :: InputThumbnail -> InputThumbnail -> Bool
$c/= :: InputThumbnail -> InputThumbnail -> Bool
/= :: InputThumbnail -> InputThumbnail -> Bool
Eq, Int -> InputThumbnail -> ShowS
[InputThumbnail] -> ShowS
InputThumbnail -> String
(Int -> InputThumbnail -> ShowS)
-> (InputThumbnail -> String)
-> ([InputThumbnail] -> ShowS)
-> Show InputThumbnail
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputThumbnail -> ShowS
showsPrec :: Int -> InputThumbnail -> ShowS
$cshow :: InputThumbnail -> String
show :: InputThumbnail -> String
$cshowList :: [InputThumbnail] -> ShowS
showList :: [InputThumbnail] -> ShowS
Show)

instance I.ShortShow InputThumbnail where
  shortShow :: InputThumbnail -> String
shortShow InputThumbnail
    { thumbnail :: InputThumbnail -> Maybe InputFile
thumbnail = Maybe InputFile
thumbnail_
    , width :: InputThumbnail -> Maybe Int
width     = Maybe Int
width_
    , height :: InputThumbnail -> Maybe Int
height    = Maybe Int
height_
    }
      = String
"InputThumbnail"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"thumbnail" String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
thumbnail_
        , 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 InputThumbnail where
  parseJSON :: Value -> Parser InputThumbnail
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
"inputThumbnail" -> Value -> Parser InputThumbnail
parseInputThumbnail Value
v
      String
_                -> Parser InputThumbnail
forall a. Monoid a => a
mempty
    
    where
      parseInputThumbnail :: A.Value -> AT.Parser InputThumbnail
      parseInputThumbnail :: Value -> Parser InputThumbnail
parseInputThumbnail = String
-> (Object -> Parser InputThumbnail)
-> Value
-> Parser InputThumbnail
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputThumbnail" ((Object -> Parser InputThumbnail)
 -> Value -> Parser InputThumbnail)
-> (Object -> Parser InputThumbnail)
-> Value
-> Parser InputThumbnail
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe InputFile
thumbnail_ <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"thumbnail"
        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"
        InputThumbnail -> Parser InputThumbnail
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputThumbnail -> Parser InputThumbnail)
-> InputThumbnail -> Parser InputThumbnail
forall a b. (a -> b) -> a -> b
$ InputThumbnail
          { thumbnail :: Maybe InputFile
thumbnail = Maybe InputFile
thumbnail_
          , width :: Maybe Int
width     = Maybe Int
width_
          , height :: Maybe Int
height    = Maybe Int
height_
          }
  parseJSON Value
_ = Parser InputThumbnail
forall a. Monoid a => a
mempty

instance AT.ToJSON InputThumbnail where
  toJSON :: InputThumbnail -> Value
toJSON InputThumbnail
    { thumbnail :: InputThumbnail -> Maybe InputFile
thumbnail = Maybe InputFile
thumbnail_
    , width :: InputThumbnail -> Maybe Int
width     = Maybe Int
width_
    , height :: InputThumbnail -> 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
"inputThumbnail"
        , Key
"thumbnail" Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
thumbnail_
        , 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_
        ]

defaultInputThumbnail :: InputThumbnail
defaultInputThumbnail :: InputThumbnail
defaultInputThumbnail =
  InputThumbnail
    { thumbnail :: Maybe InputFile
thumbnail = Maybe InputFile
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
    }