module TD.Query.FinishFileGeneration
  (FinishFileGeneration(..)
  , defaultFinishFileGeneration
  ) 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.Error as Error

-- | Finishes the file generation. Returns 'TD.Data.Ok.Ok'
data FinishFileGeneration
  = FinishFileGeneration
    { FinishFileGeneration -> Maybe Int
generation_id :: Maybe Int         -- ^ The identifier of the generation process
    , FinishFileGeneration -> Maybe Error
_error        :: Maybe Error.Error -- ^ If passed, the file generation has failed and must be terminated; pass null if the file generation succeeded
    }
  deriving (FinishFileGeneration -> FinishFileGeneration -> Bool
(FinishFileGeneration -> FinishFileGeneration -> Bool)
-> (FinishFileGeneration -> FinishFileGeneration -> Bool)
-> Eq FinishFileGeneration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FinishFileGeneration -> FinishFileGeneration -> Bool
== :: FinishFileGeneration -> FinishFileGeneration -> Bool
$c/= :: FinishFileGeneration -> FinishFileGeneration -> Bool
/= :: FinishFileGeneration -> FinishFileGeneration -> Bool
Eq, Int -> FinishFileGeneration -> ShowS
[FinishFileGeneration] -> ShowS
FinishFileGeneration -> String
(Int -> FinishFileGeneration -> ShowS)
-> (FinishFileGeneration -> String)
-> ([FinishFileGeneration] -> ShowS)
-> Show FinishFileGeneration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FinishFileGeneration -> ShowS
showsPrec :: Int -> FinishFileGeneration -> ShowS
$cshow :: FinishFileGeneration -> String
show :: FinishFileGeneration -> String
$cshowList :: [FinishFileGeneration] -> ShowS
showList :: [FinishFileGeneration] -> ShowS
Show)

instance I.ShortShow FinishFileGeneration where
  shortShow :: FinishFileGeneration -> String
shortShow
    FinishFileGeneration
      { generation_id :: FinishFileGeneration -> Maybe Int
generation_id = Maybe Int
generation_id_
      , _error :: FinishFileGeneration -> Maybe Error
_error        = Maybe Error
_error_
      }
        = String
"FinishFileGeneration"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"generation_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
generation_id_
          , String
"_error"        String -> Maybe Error -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Error
_error_
          ]

instance AT.ToJSON FinishFileGeneration where
  toJSON :: FinishFileGeneration -> Value
toJSON
    FinishFileGeneration
      { generation_id :: FinishFileGeneration -> Maybe Int
generation_id = Maybe Int
generation_id_
      , _error :: FinishFileGeneration -> Maybe Error
_error        = Maybe Error
_error_
      }
        = [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
"finishFileGeneration"
          , Key
"generation_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
generation_id_
          , Key
"error"         Key -> Maybe Error -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Error
_error_
          ]

defaultFinishFileGeneration :: FinishFileGeneration
defaultFinishFileGeneration :: FinishFileGeneration
defaultFinishFileGeneration =
  FinishFileGeneration
    { generation_id :: Maybe Int
generation_id = Maybe Int
forall a. Maybe a
Nothing
    , _error :: Maybe Error
_error        = Maybe Error
forall a. Maybe a
Nothing
    }