    {-# LANGUAGE OverloadedStrings    #-}
    {- |
       Module      : Text.Pandoc.Lua.Marshal.CommonState
       Copyright   : © 2012-2024 John MacFarlane
                     © 2017-2024 Albert Krewinkel
       License     : GNU GPL, version 2 or above
       Maintainer  : Albert Krewinkel <albert+pandoc@tarleb.com>
       Stability   : alpha

    Instances to marshal (push) and unmarshal (peek) the common state.
    -}
    module Text.Pandoc.Lua.Marshal.CommonState
      ( typeCommonState
      , peekCommonState
      , pushCommonState
      ) where

    import HsLua
    import Text.Pandoc.Class (CommonState (..))
    import Text.Pandoc.Lua.Marshal.List (pushPandocList)
    import Text.Pandoc.Lua.Marshal.LogMessage (pushLogMessage)

    -- | Lua type used for the @CommonState@ object.
    typeCommonState :: LuaError e => DocumentedType e CommonState
    typeCommonState :: forall e. LuaError e => DocumentedType e CommonState
    typeCommonState = Name
    -> [(Operation, DocumentedFunction e)]
    -> [Member e (DocumentedFunction e) CommonState]
    -> DocumentedType e CommonState
    forall e a.
    LuaError e =>
    Name
    -> [(Operation, DocumentedFunction e)]
    -> [Member e (DocumentedFunction e) a]
    -> DocumentedType e a
    deftype Name
    "CommonState" []
      [ Name
    -> Text
    -> (Pusher e [String], CommonState -> [String])
    -> Member e (DocumentedFunction e) CommonState
    forall e b a fn.
    Name -> Text -> (Pusher e b, a -> b) -> Member e fn a
    readonly Name
    "input_files" Text
    "input files passed to pandoc"
          (Pusher e String -> Pusher e [String]
    forall e a. LuaError e => Pusher e a -> Pusher e [a]
    pushPandocList Pusher e String
    forall e. String -> LuaE e ()
    pushString, CommonState -> [String]
    stInputFiles)

      , Name
    -> Text
    -> (Pusher e (Maybe String), CommonState -> Maybe String)
    -> Member e (DocumentedFunction e) CommonState
    forall e b a fn.
    Name -> Text -> (Pusher e b, a -> b) -> Member e fn a
    readonly Name
    "output_file" Text
    "the file to which pandoc will write"
          (LuaE e () -> Pusher e String -> Pusher e (Maybe String)
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe LuaE e ()
    forall e. LuaE e ()
    pushnil Pusher e String
    forall e. String -> LuaE e ()
    pushString, CommonState -> Maybe String
    stOutputFile)

      , Name
    -> Text
    -> (Pusher e [LogMessage], CommonState -> [LogMessage])
    -> Member e (DocumentedFunction e) CommonState
    forall e b a fn.
    Name -> Text -> (Pusher e b, a -> b) -> Member e fn a
    readonly Name
    "log" Text
    "list of log messages"
          (Pusher e LogMessage -> Pusher e [LogMessage]
    forall e a. LuaError e => Pusher e a -> Pusher e [a]
    pushPandocList Pusher e LogMessage
    forall e. LuaError e => Pusher e LogMessage
    pushLogMessage, CommonState -> [LogMessage]
    stLog)

      , Name
    -> Text
    -> (Pusher e [(Text, Text)], CommonState -> [(Text, Text)])
    -> Member e (DocumentedFunction e) CommonState
    forall e b a fn.
    Name -> Text -> (Pusher e b, a -> b) -> Member e fn a
    readonly Name
    "request_headers" Text
    "headers to add for HTTP requests"
          (Pusher e (Text, Text) -> Pusher e [(Text, Text)]
    forall e a. LuaError e => Pusher e a -> Pusher e [a]
    pushPandocList (Pusher e Text -> Pusher e Text -> Pusher e (Text, Text)
    forall e a b.
    LuaError e =>
    Pusher e a -> Pusher e b -> (a, b) -> LuaE e ()
    pushPair Pusher e Text
    forall e. Pusher e Text
    pushText Pusher e Text
    forall e. Pusher e Text
    pushText), CommonState -> [(Text, Text)]
    stRequestHeaders)

      , Name
    -> Text
    -> (Pusher e [String], CommonState -> [String])
    -> Member e (DocumentedFunction e) CommonState
    forall e b a fn.
    Name -> Text -> (Pusher e b, a -> b) -> Member e fn a
    readonly Name
    "resource_path"
          Text
    "path to search for resources like included images"
          (Pusher e String -> Pusher e [String]
    forall e a. LuaError e => Pusher e a -> Pusher e [a]
    pushPandocList Pusher e String
    forall e. String -> LuaE e ()
    pushString, CommonState -> [String]
    stResourcePath)

      , Name
    -> Text
    -> (Pusher e (Maybe Text), CommonState -> Maybe Text)
    -> Member e (DocumentedFunction e) CommonState
    forall e b a fn.
    Name -> Text -> (Pusher e b, a -> b) -> Member e fn a
    readonly Name
    "source_url" Text
    "absolute URL + dir of 1st source file"
          (LuaE e () -> Pusher e Text -> Pusher e (Maybe Text)
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe LuaE e ()
    forall e. LuaE e ()
    pushnil Pusher e Text
    forall e. Pusher e Text
    pushText, CommonState -> Maybe Text
    stSourceURL)

      , Name
    -> Text
    -> (Pusher e (Maybe String), CommonState -> Maybe String)
    -> Member e (DocumentedFunction e) CommonState
    forall e b a fn.
    Name -> Text -> (Pusher e b, a -> b) -> Member e fn a
    readonly Name
    "user_data_dir" Text
    "directory to search for data files"
          (LuaE e () -> Pusher e String -> Pusher e (Maybe String)
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe LuaE e ()
    forall e. LuaE e ()
    pushnil Pusher e String
    forall e. String -> LuaE e ()
    pushString, CommonState -> Maybe String
    stUserDataDir)

      , Name
    -> Text
    -> (Pusher e Bool, CommonState -> Bool)
    -> Member e (DocumentedFunction e) CommonState
    forall e b a fn.
    Name -> Text -> (Pusher e b, a -> b) -> Member e fn a
    readonly Name
    "trace" Text
    "controls whether tracing messages are issued"
          (Pusher e Bool
    forall e. Pusher e Bool
    pushBool, CommonState -> Bool
    stTrace)

      , Name
    -> Text
    -> (Pusher e Verbosity, CommonState -> Verbosity)
    -> Member e (DocumentedFunction e) CommonState
    forall e b a fn.
    Name -> Text -> (Pusher e b, a -> b) -> Member e fn a
    readonly Name
    "verbosity" Text
    "verbosity level"
          (Pusher e String
    forall e. String -> LuaE e ()
    pushString Pusher e String -> (Verbosity -> String) -> Pusher e Verbosity
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Verbosity -> String
    forall a. Show a => a -> String
    show, CommonState -> Verbosity
    stVerbosity)
      ]

    peekCommonState :: LuaError e => Peeker e CommonState
    peekCommonState :: forall e. LuaError e => Peeker e CommonState
    peekCommonState = DocumentedTypeWithList e CommonState Void -> Peeker e CommonState
    forall e a itemtype.
    LuaError e =>
    DocumentedTypeWithList e a itemtype -> Peeker e a
    peekUD DocumentedTypeWithList e CommonState Void
    forall e. LuaError e => DocumentedType e CommonState
    typeCommonState

    pushCommonState :: LuaError e => Pusher e CommonState
    pushCommonState :: forall e. LuaError e => Pusher e CommonState
    pushCommonState = DocumentedTypeWithList e CommonState Void
    -> CommonState -> LuaE e ()
    forall e a itemtype.
    LuaError e =>
    DocumentedTypeWithList e a itemtype -> a -> LuaE e ()
    pushUD DocumentedTypeWithList e CommonState Void
    forall e. LuaError e => DocumentedType e CommonState
    typeCommonState