module TD.Data.InputAudio
  ( InputAudio(..)    
  , defaultInputAudio 
  ) 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
import qualified Data.Text as T

data InputAudio
  = InputAudio -- ^ An audio to be sent
    { InputAudio -> Maybe InputFile
audio                 :: Maybe InputFile.InputFile           -- ^ Audio file to be sent
    , InputAudio -> Maybe InputThumbnail
album_cover_thumbnail :: Maybe InputThumbnail.InputThumbnail -- ^ Thumbnail of the cover for the album; pass null to skip thumbnail uploading
    , InputAudio -> Maybe Int
duration              :: Maybe Int                           -- ^ Duration of the audio, in seconds; may be replaced by the server
    , InputAudio -> Maybe Text
title                 :: Maybe T.Text                        -- ^ Title of the audio; 0-64 characters; may be replaced by the server
    , InputAudio -> Maybe Text
performer             :: Maybe T.Text                        -- ^ Performer of the audio; 0-64 characters, may be replaced by the server
    }
  deriving (InputAudio -> InputAudio -> Bool
(InputAudio -> InputAudio -> Bool)
-> (InputAudio -> InputAudio -> Bool) -> Eq InputAudio
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputAudio -> InputAudio -> Bool
== :: InputAudio -> InputAudio -> Bool
$c/= :: InputAudio -> InputAudio -> Bool
/= :: InputAudio -> InputAudio -> Bool
Eq, Int -> InputAudio -> ShowS
[InputAudio] -> ShowS
InputAudio -> String
(Int -> InputAudio -> ShowS)
-> (InputAudio -> String)
-> ([InputAudio] -> ShowS)
-> Show InputAudio
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputAudio -> ShowS
showsPrec :: Int -> InputAudio -> ShowS
$cshow :: InputAudio -> String
show :: InputAudio -> String
$cshowList :: [InputAudio] -> ShowS
showList :: [InputAudio] -> ShowS
Show)

instance I.ShortShow InputAudio where
  shortShow :: InputAudio -> String
shortShow InputAudio
    { audio :: InputAudio -> Maybe InputFile
audio                 = Maybe InputFile
audio_
    , album_cover_thumbnail :: InputAudio -> Maybe InputThumbnail
album_cover_thumbnail = Maybe InputThumbnail
album_cover_thumbnail_
    , duration :: InputAudio -> Maybe Int
duration              = Maybe Int
duration_
    , title :: InputAudio -> Maybe Text
title                 = Maybe Text
title_
    , performer :: InputAudio -> Maybe Text
performer             = Maybe Text
performer_
    }
      = String
"InputAudio"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"audio"                 String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
audio_
        , String
"album_cover_thumbnail" String -> Maybe InputThumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputThumbnail
album_cover_thumbnail_
        , String
"duration"              String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
duration_
        , String
"title"                 String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"performer"             String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
performer_
        ]

instance AT.FromJSON InputAudio where
  parseJSON :: Value -> Parser InputAudio
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
"inputAudio" -> Value -> Parser InputAudio
parseInputAudio Value
v
      String
_            -> Parser InputAudio
forall a. Monoid a => a
mempty
    
    where
      parseInputAudio :: A.Value -> AT.Parser InputAudio
      parseInputAudio :: Value -> Parser InputAudio
parseInputAudio = String
-> (Object -> Parser InputAudio) -> Value -> Parser InputAudio
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputAudio" ((Object -> Parser InputAudio) -> Value -> Parser InputAudio)
-> (Object -> Parser InputAudio) -> Value -> Parser InputAudio
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe InputFile
audio_                 <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"audio"
        Maybe InputThumbnail
album_cover_thumbnail_ <- Object
o Object -> Key -> Parser (Maybe InputThumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"album_cover_thumbnail"
        Maybe Int
duration_              <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"duration"
        Maybe Text
title_                 <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        Maybe Text
performer_             <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"performer"
        InputAudio -> Parser InputAudio
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputAudio -> Parser InputAudio)
-> InputAudio -> Parser InputAudio
forall a b. (a -> b) -> a -> b
$ InputAudio
          { audio :: Maybe InputFile
audio                 = Maybe InputFile
audio_
          , album_cover_thumbnail :: Maybe InputThumbnail
album_cover_thumbnail = Maybe InputThumbnail
album_cover_thumbnail_
          , duration :: Maybe Int
duration              = Maybe Int
duration_
          , title :: Maybe Text
title                 = Maybe Text
title_
          , performer :: Maybe Text
performer             = Maybe Text
performer_
          }
  parseJSON Value
_ = Parser InputAudio
forall a. Monoid a => a
mempty

instance AT.ToJSON InputAudio where
  toJSON :: InputAudio -> Value
toJSON InputAudio
    { audio :: InputAudio -> Maybe InputFile
audio                 = Maybe InputFile
audio_
    , album_cover_thumbnail :: InputAudio -> Maybe InputThumbnail
album_cover_thumbnail = Maybe InputThumbnail
album_cover_thumbnail_
    , duration :: InputAudio -> Maybe Int
duration              = Maybe Int
duration_
    , title :: InputAudio -> Maybe Text
title                 = Maybe Text
title_
    , performer :: InputAudio -> Maybe Text
performer             = Maybe Text
performer_
    }
      = [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
"inputAudio"
        , Key
"audio"                 Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
audio_
        , Key
"album_cover_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
album_cover_thumbnail_
        , Key
"duration"              Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
duration_
        , Key
"title"                 Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
title_
        , Key
"performer"             Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
performer_
        ]

defaultInputAudio :: InputAudio
defaultInputAudio :: InputAudio
defaultInputAudio =
  InputAudio
    { audio :: Maybe InputFile
audio                 = Maybe InputFile
forall a. Maybe a
Nothing
    , album_cover_thumbnail :: Maybe InputThumbnail
album_cover_thumbnail = Maybe InputThumbnail
forall a. Maybe a
Nothing
    , duration :: Maybe Int
duration              = Maybe Int
forall a. Maybe a
Nothing
    , title :: Maybe Text
title                 = Maybe Text
forall a. Maybe a
Nothing
    , performer :: Maybe Text
performer             = Maybe Text
forall a. Maybe a
Nothing
    }