    {-# LANGUAGE OverloadedStrings    #-}
    {- |
    Copyright               : © 2021-2026 Albert Krewinkel
    SPDX-License-Identifier : MIT
    Maintainer              : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>

    Marshaling/unmarshaling functions of 'TableFoot' values.
    -}
    module Text.Pandoc.Lua.Marshal.TableFoot
      ( peekTableFoot
      , pushTableFoot
      , typeTableFoot
      , mkTableFoot
      ) where

    import Control.Applicative (optional)
    import Data.Aeson (encode)
    import Data.Maybe (fromMaybe)
    import HsLua
    import Text.Pandoc.Lua.Marshal.Attr (peekAttr, pushAttr)
    import Text.Pandoc.Lua.Marshal.List (pushPandocList)
    import Text.Pandoc.Lua.Marshal.Row (peekRowFuzzy, pushRow)
    import Text.Pandoc.Definition

    -- | Push a TableFoot as a userdata value.
    pushTableFoot :: LuaError e => TableFoot -> LuaE e ()
    pushTableFoot :: forall e. LuaError e => TableFoot -> LuaE e ()
    pushTableFoot = DocumentedTypeWithList e TableFoot (ZonkAny 2)
    -> TableFoot -> LuaE e ()
    forall e a itemtype.
    LuaError e =>
    DocumentedTypeWithList e a itemtype -> a -> LuaE e ()
    pushUD DocumentedTypeWithList e TableFoot (ZonkAny 2)
    forall e. LuaError e => DocumentedType e TableFoot
    typeTableFoot

    -- | Retrieves a TableFoot from the stack.
    peekTableFoot :: LuaError e => Peeker e TableFoot
    peekTableFoot :: forall e. LuaError e => Peeker e TableFoot
    peekTableFoot = DocumentedTypeWithList e TableFoot (ZonkAny 0)
    -> Peeker e TableFoot
    forall e a itemtype.
    LuaError e =>
    DocumentedTypeWithList e a itemtype -> Peeker e a
    peekUD DocumentedTypeWithList e TableFoot (ZonkAny 0)
    forall e. LuaError e => DocumentedType e TableFoot
    typeTableFoot

    -- | TableFoot object type.
    typeTableFoot :: LuaError e => DocumentedType e TableFoot
    typeTableFoot :: forall e. LuaError e => DocumentedType e TableFoot
    typeTableFoot = Name
    -> [(Operation, DocumentedFunction e)]
    -> [Member e (DocumentedFunction e) TableFoot]
    -> DocumentedType e TableFoot
    forall e a.
    LuaError e =>
    Name
    -> [(Operation, DocumentedFunction e)]
    -> [Member e (DocumentedFunction e) a]
    -> DocumentedType e a
    deftype Name
    "TableFoot"
      [ Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall e.
    Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    operation Operation
    Eq (DocumentedFunction e -> (Operation, DocumentedFunction e))
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall a b. (a -> b) -> a -> b
    $ Name
    -> (Maybe TableFoot -> Maybe TableFoot -> LuaE e Bool)
    -> HsFnPrecursor
         e (Maybe TableFoot -> Maybe TableFoot -> LuaE e Bool)
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "__eq"
         ### liftPure2 (\a b -> fromMaybe False ((==) <$> a <*> b))
         HsFnPrecursor e (Maybe TableFoot -> Maybe TableFoot -> LuaE e Bool)
    -> Parameter e (Maybe TableFoot)
    -> HsFnPrecursor e (Maybe TableFoot -> LuaE e Bool)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Peeker e (Maybe TableFoot)
    -> TypeSpec -> Text -> Text -> Parameter e (Maybe TableFoot)
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter (Peek e TableFoot -> Peek e (Maybe TableFoot)
    forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
    optional (Peek e TableFoot -> Peek e (Maybe TableFoot))
    -> (StackIndex -> Peek e TableFoot) -> Peeker e (Maybe TableFoot)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StackIndex -> Peek e TableFoot
    forall e. LuaError e => Peeker e TableFoot
    peekTableFoot) TypeSpec
    "TableFoot" Text
    "self" Text
    ""
         HsFnPrecursor e (Maybe TableFoot -> LuaE e Bool)
    -> Parameter e (Maybe TableFoot) -> HsFnPrecursor e (LuaE e Bool)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Peeker e (Maybe TableFoot)
    -> TypeSpec -> Text -> Text -> Parameter e (Maybe TableFoot)
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter (Peek e TableFoot -> Peek e (Maybe TableFoot)
    forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
    optional (Peek e TableFoot -> Peek e (Maybe TableFoot))
    -> (StackIndex -> Peek e TableFoot) -> Peeker e (Maybe TableFoot)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StackIndex -> Peek e TableFoot
    forall e. LuaError e => Peeker e TableFoot
    peekTableFoot) TypeSpec
    "any" Text
    "object" Text
    ""
         HsFnPrecursor e (LuaE e Bool)
    -> FunctionResults e Bool -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Pusher e Bool -> TypeSpec -> Text -> FunctionResults e Bool
    forall e a. Pusher e a -> TypeSpec -> Text -> FunctionResults e a
    functionResult Pusher e Bool
    forall e. Pusher e Bool
    pushBool TypeSpec
    "boolean" Text
    "true iff the two values are equal"
      , Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall e.
    Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    operation Operation
    Tostring (DocumentedFunction e -> (Operation, DocumentedFunction e))
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall a b. (a -> b) -> a -> b
    $ (TableFoot -> LuaE e String)
    -> HsFnPrecursor e (TableFoot -> LuaE e String)
    forall a e. a -> HsFnPrecursor e a
    lambda
        ### liftPure show
        HsFnPrecursor e (TableFoot -> LuaE e String)
    -> Parameter e TableFoot -> HsFnPrecursor e (LuaE e String)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> (StackIndex -> Peek e TableFoot)
    -> TypeSpec -> Text -> Text -> Parameter e TableFoot
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter StackIndex -> Peek e TableFoot
    forall e. LuaError e => Peeker e TableFoot
    peekTableFoot TypeSpec
    "TableFoot" Text
    "self" Text
    ""
        HsFnPrecursor e (LuaE e String)
    -> FunctionResults e String -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Pusher e String -> TypeSpec -> Text -> FunctionResults e String
    forall e a. Pusher e a -> TypeSpec -> Text -> FunctionResults e a
    functionResult Pusher e String
    forall e. String -> LuaE e ()
    pushString TypeSpec
    "string" Text
    "native Haskell representation"
      , Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall e.
    Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    operation (Name -> Operation
    CustomOperation Name
    "__tojson") (DocumentedFunction e -> (Operation, DocumentedFunction e))
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall a b. (a -> b) -> a -> b
    $ (TableFoot -> LuaE e ByteString)
    -> HsFnPrecursor e (TableFoot -> LuaE e ByteString)
    forall a e. a -> HsFnPrecursor e a
    lambda
        ### liftPure encode
        HsFnPrecursor e (TableFoot -> LuaE e ByteString)
    -> Parameter e TableFoot -> HsFnPrecursor e (LuaE e ByteString)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> DocumentedType e TableFoot -> Text -> Text -> Parameter e TableFoot
    forall e a itemtype.
    LuaError e =>
    DocumentedTypeWithList e a itemtype
    -> Text -> Text -> Parameter e a
    udparam DocumentedType e TableFoot
    forall e. LuaError e => DocumentedType e TableFoot
    typeTableFoot Text
    "self" Text
    ""
        HsFnPrecursor e (LuaE e ByteString)
    -> FunctionResults e ByteString -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Pusher e ByteString
    -> TypeSpec -> Text -> FunctionResults e ByteString
    forall e a. Pusher e a -> TypeSpec -> Text -> FunctionResults e a
    functionResult Pusher e ByteString
    forall e. Pusher e ByteString
    pushLazyByteString TypeSpec
    "string" Text
    "JSON representation"
      ]
      [ Name
    -> Text
    -> (Pusher e Attr, TableFoot -> Attr)
    -> (Peeker e Attr, TableFoot -> Attr -> TableFoot)
    -> Member e (DocumentedFunction e) TableFoot
    forall e b a fn.
    LuaError e =>
    Name
    -> Text
    -> (Pusher e b, a -> b)
    -> (Peeker e b, a -> b -> a)
    -> Member e fn a
    property Name
    "attr" Text
    "table foot attributes"
          (Pusher e Attr
    forall e. LuaError e => Pusher e Attr
    pushAttr, \(TableFoot Attr
    attr [Row]
    _) -> Attr
    attr)
          (Peeker e Attr
    forall e. LuaError e => Peeker e Attr
    peekAttr, \(TableFoot Attr
    _ [Row]
    cells) Attr
    attr ->
                       Attr -> [Row] -> TableFoot
    TableFoot Attr
    attr [Row]
    cells)
      , Name
    -> Text
    -> (Pusher e [Row], TableFoot -> [Row])
    -> (Peeker e [Row], TableFoot -> [Row] -> TableFoot)
    -> Member e (DocumentedFunction e) TableFoot
    forall e b a fn.
    LuaError e =>
    Name
    -> Text
    -> (Pusher e b, a -> b)
    -> (Peeker e b, a -> b -> a)
    -> Member e fn a
    property Name
    "rows" Text
    "footer rows"
          (Pusher e Row -> Pusher e [Row]
    forall e a. LuaError e => Pusher e a -> Pusher e [a]
    pushPandocList Pusher e Row
    forall e. LuaError e => Row -> LuaE e ()
    pushRow, \(TableFoot Attr
    _ [Row]
    rows) -> [Row]
    rows)
          (Peeker e Row -> Peeker e [Row]
    forall a e. LuaError e => Peeker e a -> Peeker e [a]
    peekList Peeker e Row
    forall e. LuaError e => Peeker e Row
    peekRowFuzzy, \(TableFoot Attr
    attr [Row]
    _) [Row]
    rows ->
                                    Attr -> [Row] -> TableFoot
    TableFoot Attr
    attr [Row]
    rows)

      , AliasIndex
    -> Text
    -> [AliasIndex]
    -> Member e (DocumentedFunction e) TableFoot
    forall e fn a. AliasIndex -> Text -> [AliasIndex] -> Member e fn a
    alias AliasIndex
    "identifier" Text
    "cell ID"         [AliasIndex
    "attr", AliasIndex
    "identifier"]
      , AliasIndex
    -> Text
    -> [AliasIndex]
    -> Member e (DocumentedFunction e) TableFoot
    forall e fn a. AliasIndex -> Text -> [AliasIndex] -> Member e fn a
    alias AliasIndex
    "classes"    Text
    "cell classes"    [AliasIndex
    "attr", AliasIndex
    "classes"]
      , AliasIndex
    -> Text
    -> [AliasIndex]
    -> Member e (DocumentedFunction e) TableFoot
    forall e fn a. AliasIndex -> Text -> [AliasIndex] -> Member e fn a
    alias AliasIndex
    "attributes" Text
    "cell attributes" [AliasIndex
    "attr", AliasIndex
    "attributes"]

      , DocumentedFunction e -> Member e (DocumentedFunction e) TableFoot
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method (DocumentedFunction e -> Member e (DocumentedFunction e) TableFoot)
    -> DocumentedFunction e
    -> Member e (DocumentedFunction e) TableFoot
    forall a b. (a -> b) -> a -> b
    $ Name
    -> (TableFoot -> LuaE e TableFoot)
    -> HsFnPrecursor e (TableFoot -> LuaE e TableFoot)
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "clone"
        ### return
        HsFnPrecursor e (TableFoot -> LuaE e TableFoot)
    -> Parameter e TableFoot -> HsFnPrecursor e (LuaE e TableFoot)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> (StackIndex -> Peek e TableFoot)
    -> TypeSpec -> Text -> Text -> Parameter e TableFoot
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter StackIndex -> Peek e TableFoot
    forall e. LuaError e => Peeker e TableFoot
    peekTableFoot TypeSpec
    "TableFoot" Text
    "self" Text
    ""
        HsFnPrecursor e (LuaE e TableFoot)
    -> FunctionResults e TableFoot -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Pusher e TableFoot
    -> TypeSpec -> Text -> FunctionResults e TableFoot
    forall e a. Pusher e a -> TypeSpec -> Text -> FunctionResults e a
    functionResult Pusher e TableFoot
    forall e. LuaError e => TableFoot -> LuaE e ()
    pushTableFoot TypeSpec
    "TableFoot" Text
    "cloned object"
      ]

    -- | Constructor function for TableFoot values.
    mkTableFoot :: LuaError e => DocumentedFunction e
    mkTableFoot :: forall e. LuaError e => DocumentedFunction e
    mkTableFoot = Name
    -> (Maybe [Row] -> Maybe Attr -> LuaE e TableFoot)
    -> HsFnPrecursor e (Maybe [Row] -> Maybe Attr -> LuaE e TableFoot)
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "TableFoot"
      ### liftPure2 (\mCells mAttr -> TableFoot
                      (fromMaybe nullAttr mAttr)
                      (fromMaybe [] mCells))
      HsFnPrecursor e (Maybe [Row] -> Maybe Attr -> LuaE e TableFoot)
    -> Parameter e (Maybe [Row])
    -> HsFnPrecursor e (Maybe Attr -> LuaE e TableFoot)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Parameter e [Row] -> Parameter e (Maybe [Row])
    forall e a. Parameter e a -> Parameter e (Maybe a)
    opt (Peeker e [Row] -> TypeSpec -> Text -> Text -> Parameter e [Row]
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter (Peeker e Row -> Peeker e [Row]
    forall a e. LuaError e => Peeker e a -> Peeker e [a]
    peekList Peeker e Row
    forall e. LuaError e => Peeker e Row
    peekRowFuzzy) TypeSpec
    "{Row,...}" Text
    "rows"
               Text
    "list of table rows")
      HsFnPrecursor e (Maybe Attr -> LuaE e TableFoot)
    -> Parameter e (Maybe Attr) -> HsFnPrecursor e (LuaE e TableFoot)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Parameter e Attr -> Parameter e (Maybe Attr)
    forall e a. Parameter e a -> Parameter e (Maybe a)
    opt (Peeker e Attr -> TypeSpec -> Text -> Text -> Parameter e Attr
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter Peeker e Attr
    forall e. LuaError e => Peeker e Attr
    peekAttr TypeSpec
    "Attr" Text
    "attr" Text
    "table foot attributes")
      HsFnPrecursor e (LuaE e TableFoot)
    -> FunctionResults e TableFoot -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Pusher e TableFoot
    -> TypeSpec -> Text -> FunctionResults e TableFoot
    forall e a. Pusher e a -> TypeSpec -> Text -> FunctionResults e a
    functionResult Pusher e TableFoot
    forall e. LuaError e => TableFoot -> LuaE e ()
    pushTableFoot TypeSpec
    "TableFoot" Text
    "new TableFoot object"
      #? "Creates a table foot."