{-# LANGUAGE OverloadedStrings    #-}
{- |
Copyright               : © 2021-2022 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.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 :: TableFoot -> LuaE e ()
pushTableFoot = UDTypeWithList e (DocumentedFunction e) TableFoot Void
-> TableFoot -> LuaE e ()
forall e fn a itemtype.
LuaError e =>
UDTypeWithList e fn a itemtype -> a -> LuaE e ()
pushUD UDTypeWithList e (DocumentedFunction e) TableFoot Void
forall e. LuaError e => DocumentedType e TableFoot
typeTableFoot

-- | Retrieves a 'Cell' from the stack.
peekTableFoot :: LuaError e => Peeker e TableFoot
peekTableFoot :: Peeker e TableFoot
peekTableFoot = UDTypeWithList e (DocumentedFunction e) TableFoot Void
-> Peeker e TableFoot
forall e fn a itemtype.
LuaError e =>
UDTypeWithList e fn a itemtype -> Peeker e a
peekUD UDTypeWithList e (DocumentedFunction e) TableFoot Void
forall e. LuaError e => DocumentedType e TableFoot
typeTableFoot

-- | Row object type.
typeTableFoot :: LuaError e => DocumentedType e TableFoot
typeTableFoot :: 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
"pandoc 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)
-> Text -> Text -> Text -> Parameter e (Maybe TableFoot)
forall e a. Peeker e a -> Text -> 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) Text
"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)
-> Text -> Text -> Text -> Parameter e (Maybe TableFoot)
forall e a. Peeker e a -> Text -> 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) Text
"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 -> Text -> Text -> FunctionResults e Bool
forall e a. Pusher e a -> Text -> Text -> FunctionResults e a
functionResult Pusher e Bool
forall e. Pusher e Bool
pushBool Text
"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)
-> Text -> Text -> Text -> Parameter e TableFoot
forall e a. Peeker e a -> Text -> Text -> Text -> Parameter e a
parameter StackIndex -> Peek e TableFoot
forall e. LuaError e => Peeker e TableFoot
peekTableFoot Text
"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 -> Text -> Text -> FunctionResults e String
forall e a. Pusher e a -> Text -> Text -> FunctionResults e a
functionResult Pusher e String
forall e. String -> LuaE e ()
pushString Text
"string" Text
"native Haskell 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)
-> Text -> Text -> Text -> Parameter e TableFoot
forall e a. Peeker e a -> Text -> Text -> Text -> Parameter e a
parameter StackIndex -> Peek e TableFoot
forall e. LuaError e => Peeker e TableFoot
peekTableFoot Text
"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 -> Text -> Text -> FunctionResults e TableFoot
forall e a. Pusher e a -> Text -> Text -> FunctionResults e a
functionResult Pusher e TableFoot
forall e. LuaError e => TableFoot -> LuaE e ()
pushTableFoot Text
"TableFoot" Text
"cloned object"
  ]

-- | Constructor function for 'Row' values.
mkTableFoot :: LuaError e => DocumentedFunction e
mkTableFoot :: 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] -> Text -> Text -> Text -> Parameter e [Row]
forall e a. Peeker e a -> Text -> 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) Text
"{Row,...}" Text
"rows" Text
"footer 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 -> Text -> Text -> Text -> Parameter e Attr
forall e a. Peeker e a -> Text -> Text -> Text -> Parameter e a
parameter Peeker e Attr
forall e. LuaError e => Peeker e Attr
peekAttr Text
"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 -> Text -> Text -> FunctionResults e TableFoot
forall e a. Pusher e a -> Text -> Text -> FunctionResults e a
functionResult Pusher e TableFoot
forall e. LuaError e => TableFoot -> LuaE e ()
pushTableFoot Text
"TableFoot" Text
"new TableFoot object"