module TD.Query.RecognizeSpeechInFile
  (RecognizeSpeechInFile(..)
  , defaultRecognizeSpeechInFile
  ) 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

-- | Recognizes speech in an audio file and returns the recognized text. The file must be in OGG format with Opus codec and must have size up to 1 MB. The same rules as for recognizeSpeech apply to the Telegram Premium requirement and speech recognition trial; must not be used in secret chats. Returns 'TD.Data.Text.Text'
data RecognizeSpeechInFile
  = RecognizeSpeechInFile
    { RecognizeSpeechInFile -> Maybe InputFile
audio_file     :: Maybe InputFile.InputFile -- ^ The audio file
    , RecognizeSpeechInFile -> Maybe Int
recognition_id :: Maybe Int                 -- ^ Unique identifier of the speech recognition, which will be used in updateSpeechRecognitionInFile to send partially recognized text; pass 0 if partial results aren't needed
    }
  deriving (RecognizeSpeechInFile -> RecognizeSpeechInFile -> Bool
(RecognizeSpeechInFile -> RecognizeSpeechInFile -> Bool)
-> (RecognizeSpeechInFile -> RecognizeSpeechInFile -> Bool)
-> Eq RecognizeSpeechInFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RecognizeSpeechInFile -> RecognizeSpeechInFile -> Bool
== :: RecognizeSpeechInFile -> RecognizeSpeechInFile -> Bool
$c/= :: RecognizeSpeechInFile -> RecognizeSpeechInFile -> Bool
/= :: RecognizeSpeechInFile -> RecognizeSpeechInFile -> Bool
Eq, Int -> RecognizeSpeechInFile -> ShowS
[RecognizeSpeechInFile] -> ShowS
RecognizeSpeechInFile -> String
(Int -> RecognizeSpeechInFile -> ShowS)
-> (RecognizeSpeechInFile -> String)
-> ([RecognizeSpeechInFile] -> ShowS)
-> Show RecognizeSpeechInFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RecognizeSpeechInFile -> ShowS
showsPrec :: Int -> RecognizeSpeechInFile -> ShowS
$cshow :: RecognizeSpeechInFile -> String
show :: RecognizeSpeechInFile -> String
$cshowList :: [RecognizeSpeechInFile] -> ShowS
showList :: [RecognizeSpeechInFile] -> ShowS
Show)

instance I.ShortShow RecognizeSpeechInFile where
  shortShow :: RecognizeSpeechInFile -> String
shortShow
    RecognizeSpeechInFile
      { audio_file :: RecognizeSpeechInFile -> Maybe InputFile
audio_file     = Maybe InputFile
audio_file_
      , recognition_id :: RecognizeSpeechInFile -> Maybe Int
recognition_id = Maybe Int
recognition_id_
      }
        = String
"RecognizeSpeechInFile"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"audio_file"     String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
audio_file_
          , String
"recognition_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
recognition_id_
          ]

instance AT.ToJSON RecognizeSpeechInFile where
  toJSON :: RecognizeSpeechInFile -> Value
toJSON
    RecognizeSpeechInFile
      { audio_file :: RecognizeSpeechInFile -> Maybe InputFile
audio_file     = Maybe InputFile
audio_file_
      , recognition_id :: RecognizeSpeechInFile -> Maybe Int
recognition_id = Maybe Int
recognition_id_
      }
        = [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
"recognizeSpeechInFile"
          , Key
"audio_file"     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_file_
          , Key
"recognition_id" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64  Maybe Int
recognition_id_
          ]

defaultRecognizeSpeechInFile :: RecognizeSpeechInFile
defaultRecognizeSpeechInFile :: RecognizeSpeechInFile
defaultRecognizeSpeechInFile =
  RecognizeSpeechInFile
    { audio_file :: Maybe InputFile
audio_file     = Maybe InputFile
forall a. Maybe a
Nothing
    , recognition_id :: Maybe Int
recognition_id = Maybe Int
forall a. Maybe a
Nothing
    }