module Model.Types.Workflow where

import Import.NoModel

import Model.Types.Security (AuthDNF)

import qualified Data.Set as Set (toList, fromList)
import qualified Data.Map as Map
import qualified Data.Sequence as Seq
import Data.Scientific

import qualified Data.Aeson as JSON
import Data.Aeson.Types (Parser)

-- TODO remove
import Data.ByteString.Lazy.Internal (ByteString)


data WorkflowRole userid = WorkflowRoleUser userid
                         | WorkflowRoleAuthorized AuthDNF
                         | WorkflowRoleInitiator
  deriving (Eq, Ord, Show, Read, Generic, Typeable)


data WorkflowGraphNodeStatus = WGNS
  { wgnsIdent    :: CI Text
  , wgnsFinished :: Bool
  , wgnsLabel    :: Maybe Text
  }
  deriving (Eq, Ord, Show, Read, Data, Generic, Typeable)

data WorkflowGraphNode = WGN
  { wgnStatus    :: WorkflowGraphNodeStatus
  }
  deriving (Eq, Ord, Show, Read, Data, Generic, Typeable)
data WorkflowGraphNode' userid fileid = WGN'
  { wgn'Status   :: WorkflowGraphNodeStatus
  , wgn'Edges    :: Set (WorkflowGraphEdge userid fileid)
  }
  deriving (Eq, Ord, Show, Generic, Typeable)

type WorkflowGraphNodeLabel = CI Text


data WorkflowFieldPayload userid fileid (payload :: *) where
  WFPText   :: { wfptLabel  :: Text
               , wfptText   :: Text
               } -> WorkflowFieldPayload userid fileid Text
  WFPNumber :: { wfpnLabel  :: Text
               , wfpnNumber :: Scientific
               } -> WorkflowFieldPayload userid fileid Scientific
  WFPBool   :: { wfpbLabel  :: Text
               , wfpbBool   :: Bool
               } -> WorkflowFieldPayload userid fileid Bool
  WFPFile   :: { wfpfLabel  :: Text
               , wfpfFile   :: fileid
               } -> WorkflowFieldPayload userid fileid fileid
  WFPUser   :: { wfpuLabel  :: Text
               , wfpuUser   :: userid
               } -> WorkflowFieldPayload userid fileid userid

instance (Show userid, Show fileid) => Show (WorkflowFieldPayload userid fileid payload) where
  show WFPText{..}   =   "WFPText{label = " <> show wfptLabel <>   ", text = " <> show wfptText   <> "}"
  show WFPNumber{..} = "WFPNumber{label = " <> show wfpnLabel <> ", number = " <> show wfpnNumber <> "}"
  show WFPBool{..}   =   "WFPBool{label = " <> show wfpbLabel <>   ", bool = " <> show wfpbBool   <> "}"
  show WFPFile{..}   =   "WFPFile{label = " <> show wfpfLabel <>   ", file = " <> show wfpfFile   <> "}"
  show WFPUser{..}   =   "WFPUser{label = " <> show wfpuLabel <>   ", user = " <> show wfpuUser   <> "}"

data WorkflowFieldPayload' = WFPText' | WFPNumber' | WFPBool' | WFPFile' | WFPUser'
  deriving (Eq, Ord, Enum, Show, Read, Data, Generic, Typeable)


type WorkflowPayloadLabel = CI Text


data WorkflowPayloadField fileid userid (payload :: *) where
  WorkflowPayloadFieldText   :: { wepftLabel       :: Text
                                    , wepftPlaceholder :: Text
                                    , wepftTooltip     :: Maybe Text
                                    , wepftDefault     :: Maybe Text
                                    , wepftOptional    :: Maybe Bool
                                    } -> WorkflowPayloadField fileid userid Text
  WorkflowPayloadFieldNumber :: { wepfnLabel       :: Text
                                    , wepfnPlaceholder :: Text
                                    , wepfnTooltip     :: Maybe Text
                                    , wepfnDefault     :: Maybe Scientific
                                    , wepfnMin         :: Maybe Scientific
                                    , wepfnMax         :: Maybe Scientific
                                    , wepfnStep        :: Scientific
                                    , wepfnOptional    :: Maybe Bool
                                    } -> WorkflowPayloadField fileid userid Scientific
  WorkflowPayloadFieldBool   :: { wepfbLabel       :: Text
                                    , wepfbTooltip     :: Maybe Text
                                    , wepfbDefault     :: Maybe Bool
                                    } -> WorkflowPayloadField fileid userid Bool
  WorkflowPayloadFieldFile   :: { wepffLabel       :: Text
                                    , wepffTooltip     :: Maybe Text
                                    , wepffDefault     :: Maybe fileid
                                    , wepffOptional    :: Maybe Bool
                                    } -> WorkflowPayloadField fileid userid FileInfo
  WorkflowPayloadFieldUser   :: { wepfuLabel       :: Text
                                    , wepfuTooltip     :: Maybe Text
                                    , wepfuDefault     :: Maybe userid
                                    , wepfuOptional    :: Maybe Bool
                                    } -> WorkflowPayloadField fileid userid userid

instance (Show fileid, Show userid) => Show (WorkflowPayloadField fileid userid payload) where
  show (WorkflowPayloadFieldText{..}  ) = "TextField{label = " <> show wepftLabel <> ", placeholder = " <> show wepftPlaceholder <> ", tooltip = " <> show wepftTooltip <> ", default = " <> show wepftDefault <> ", optional = " <> show wepftOptional <> "}"
  show (WorkflowPayloadFieldNumber{..}) = "NumberField{label = " <> show wepfnLabel <> ", placeholder = " <> show wepfnPlaceholder <> ", tooltip = " <> show wepfnTooltip <> ", default = " <> show wepfnDefault <> ", min = " <> show wepfnMin <> ", max = " <> show wepfnMax <> ", step = " <> show wepfnStep <> ", optional = " <> show wepfnOptional <> "}"
  show (WorkflowPayloadFieldBool{..}  ) = "BoolField{label = " <> show wepfbLabel <> ", tooltip = " <> show wepfbTooltip <> ", default = " <> show wepfbDefault <> "}"
  show (WorkflowPayloadFieldFile{..}  ) = "FileField{label = " <> show wepffLabel <> ", tooltip = " <> show wepffTooltip <> ", default = " <> show wepffDefault <> ", optional = " <> show wepffOptional <> "}"
  show (WorkflowPayloadFieldUser{..}  ) = "UserField{label = " <> show wepfuLabel <> ", tooltip = " <> show wepfuTooltip <> ", default = " <> show wepfuDefault <> ", optional = " <> show wepfuOptional <> "}"



data WorkflowPayloadSpec fileid userid = forall payload. WorkflowPayloadSpec (WorkflowPayloadField fileid userid payload)

instance (Show fileid, Show userid) => Show (WorkflowPayloadSpec fileid userid) where
  show (WorkflowPayloadSpec payloadField) = show payloadField

instance (Eq fileid, Eq userid) => Eq (WorkflowPayloadSpec fileid userid) where
  (WorkflowPayloadSpec f1@WorkflowPayloadFieldText{}) == (WorkflowPayloadSpec f2@WorkflowPayloadFieldText{}) = wepftLabel f1 == wepftLabel f2 && wepftPlaceholder f1 == wepftPlaceholder f2 && wepftTooltip f1 == wepftTooltip f2 && wepftDefault f1 == wepftDefault f2 && wepftOptional f1 == wepftOptional f2
  (WorkflowPayloadSpec f1@WorkflowPayloadFieldNumber{}) == (WorkflowPayloadSpec f2@WorkflowPayloadFieldNumber{}) = wepfnLabel f1 == wepfnLabel f2 && wepfnPlaceholder f1 == wepfnPlaceholder f2 && wepfnTooltip f1 == wepfnTooltip f2 && wepfnDefault f1 == wepfnDefault f2 && wepfnOptional f1 == wepfnOptional f2
  (WorkflowPayloadSpec f1@WorkflowPayloadFieldBool{}) == (WorkflowPayloadSpec f2@WorkflowPayloadFieldBool{}) = wepfbLabel f1 == wepfbLabel f2 && wepfbTooltip f1 == wepfbTooltip f2 && wepfbDefault f1 == wepfbDefault f2
  (WorkflowPayloadSpec f1@WorkflowPayloadFieldFile{}) == (WorkflowPayloadSpec f2@WorkflowPayloadFieldFile{}) = wepffLabel f1 == wepffLabel f2 && wepffTooltip f1 == wepffTooltip f2 && wepffDefault f1 == wepffDefault f2 && wepffOptional f1 == wepffOptional f2
  (WorkflowPayloadSpec f1@WorkflowPayloadFieldUser{}) == (WorkflowPayloadSpec f2@WorkflowPayloadFieldUser{}) = wepfuLabel f1 == wepfuLabel f2 && wepfuTooltip f1 == wepfuTooltip f2 && wepfuDefault f1 == wepfuDefault f2 && wepfuOptional f1 == wepfuOptional f2
  _ == _ = False

instance (Ord fileid, Ord userid) => Ord (WorkflowPayloadSpec fileid userid) where
  compare (WorkflowPayloadSpec f1@WorkflowPayloadFieldText{}) (WorkflowPayloadSpec f2@WorkflowPayloadFieldText{}) = mconcat [comparing wepftLabel, comparing wepftPlaceholder, comparing wepftTooltip, comparing wepftDefault, comparing wepftOptional] f1 f2
  compare (WorkflowPayloadSpec f1@WorkflowPayloadFieldNumber{}) (WorkflowPayloadSpec f2@WorkflowPayloadFieldNumber{}) = mconcat [comparing wepfnLabel, comparing wepfnPlaceholder, comparing wepfnTooltip, comparing wepfnDefault, comparing wepfnMin, comparing wepfnMax, comparing wepfnStep, comparing wepfnOptional] f1 f2
  compare (WorkflowPayloadSpec f1@WorkflowPayloadFieldBool{}) (WorkflowPayloadSpec f2@WorkflowPayloadFieldBool{}) = mconcat [comparing wepfbLabel, comparing wepfbTooltip, comparing wepfbDefault] f1 f2
  compare (WorkflowPayloadSpec f1@WorkflowPayloadFieldFile{}) (WorkflowPayloadSpec f2@WorkflowPayloadFieldFile{}) = mconcat [comparing wepffLabel, comparing wepffTooltip, comparing wepffDefault, comparing wepffOptional] f1 f2
  compare (WorkflowPayloadSpec f1@WorkflowPayloadFieldUser{}) (WorkflowPayloadSpec f2@WorkflowPayloadFieldUser{}) = mconcat [comparing wepfuLabel, comparing wepfuTooltip, comparing wepfuDefault, comparing wepfuOptional] f1 f2
  compare (WorkflowPayloadSpec WorkflowPayloadFieldText{}  ) _ = LT
  compare (WorkflowPayloadSpec WorkflowPayloadFieldNumber{}) (WorkflowPayloadSpec WorkflowPayloadFieldText{}) = GT
  compare (WorkflowPayloadSpec WorkflowPayloadFieldNumber{}) _ = LT
  compare (WorkflowPayloadSpec WorkflowPayloadFieldBool{}) (WorkflowPayloadSpec WorkflowPayloadFieldText{}) = GT
  compare (WorkflowPayloadSpec WorkflowPayloadFieldBool{}) (WorkflowPayloadSpec WorkflowPayloadFieldNumber{}) = GT
  compare (WorkflowPayloadSpec WorkflowPayloadFieldBool{}) _ = LT
  compare (WorkflowPayloadSpec WorkflowPayloadFieldFile{}) (WorkflowPayloadSpec WorkflowPayloadFieldText{}) = GT
  compare (WorkflowPayloadSpec WorkflowPayloadFieldFile{}) (WorkflowPayloadSpec WorkflowPayloadFieldNumber{}) = GT
  compare (WorkflowPayloadSpec WorkflowPayloadFieldFile{}) (WorkflowPayloadSpec WorkflowPayloadFieldBool{}) = GT
  compare (WorkflowPayloadSpec WorkflowPayloadFieldFile{}) _ = LT
  compare (WorkflowPayloadSpec WorkflowPayloadFieldUser{}) _ = LT


data WorkflowPayload userid fileid = forall payload. WorkflowPayload
  { wpPayload    :: Map WorkflowPayloadLabel (Map Text (WorkflowFieldPayload userid fileid payload))
  , wpActor      :: Maybe userid
  , wpActionTime :: UTCTime
  }


data WorkflowGraphEdge userid fileid = WGE
  { wgeActors  :: Set (WorkflowRole userid)
  , wgeTarget  :: WorkflowGraphNodeLabel
  , wgeForm    :: Map WorkflowPayloadLabel (NonNull (Set (WorkflowPayloadSpec fileid userid)))
  }
  deriving Show

instance (Eq userid, Eq fileid) => Eq (WorkflowGraphEdge userid fileid) where
  e1@WGE{} == e2@WGE{} = wgeActors e1 == wgeActors e2 && wgeTarget e1 == wgeTarget e2 && wgeForm e1 == wgeForm e2
instance (Ord userid, Ord fileid) => Ord (WorkflowGraphEdge userid fileid) where
  e1@WGE{} <= e2@WGE{} = wgeActors e1 <= wgeActors e2 && wgeTarget e1 <= wgeTarget e2 && wgeForm e1 <= wgeForm e2


data WorkflowGraph userid fileid = WorkflowGraph
  { wgNodes :: Map WorkflowGraphNodeLabel (WorkflowGraphNode, Set (WorkflowGraphEdge userid fileid))
  }
  deriving Show

instance (Eq userid, Eq fileid) => Eq (WorkflowGraph userid fileid) where
  WorkflowGraph m1 == WorkflowGraph m2 = m1 == m2


data WorkflowInstanceScope term school course = WISGlobal | WISTerm term | WISSchool school | WISCourse course
  deriving (Eq, Ord, Show, Read, Data, Generic, Typeable)

data WorkflowInstanceScope' = WISGlobal' | WISTerm' | WISSchool' | WISCourse'
  deriving (Eq, Ord, Enum, Read, Show, Data, Generic, Typeable)



instance (ToJSON userid) => ToJSON (WorkflowRole userid) where
  toJSON (WorkflowRoleUser uid) = JSON.object
    [ "tag"  JSON..= ("user" :: Text)
    , "user" JSON..= uid
    ]
  toJSON (WorkflowRoleAuthorized authDNF) = JSON.object
    [ "tag"        JSON..= ("authorized" :: Text)
    , "authorized" JSON..= authDNF
    ]
  toJSON WorkflowRoleInitiator = JSON.object
    [ "tag"        JSON..= ("initiator" :: Text)
    ]
instance (FromJSON userid) => FromJSON (WorkflowRole userid) where
  parseJSON = JSON.withObject "WorkflowRole" $ \o -> do
    fieldTag <- (o JSON..: "tag" :: Parser Text)
    case fieldTag of
      "user" -> do
        uid <- o JSON..: "user"
        return $ WorkflowRoleUser uid
      "authorized" -> do
        adnf <- o JSON..: "authorized"
        return $ WorkflowRoleAuthorized adnf
      "initiator" -> return WorkflowRoleInitiator
      _ -> terror $ "WorkflowRole parseJSON error: expected role (user|authorized|initiator), but got " <> fieldTag

instance (ToJSON userid, ToJSON fileid, Ord userid) => ToJSON (WorkflowGraph userid fileid) where
  toJSON WorkflowGraph{..} = JSON.object
    [ "tag"   JSON..= ("workflow" :: Text)
    , "nodes" JSON..= Map.map (\(WGN{..},wgn'Edges) -> WGN'{wgn'Status=wgnStatus,wgn'Edges=wgn'Edges}) wgNodes
    ]
instance (FromJSON userid, FromJSON fileid, Ord userid, Ord fileid) => FromJSON (WorkflowGraph userid fileid) where
  parseJSON = JSON.withObject "WorkflowGraph" $ \o -> do
    fieldTag <- o JSON..: "tag"
    case fieldTag of
      "workflow" -> do
        wgNodes' <- (o JSON..: "nodes" :: Parser (Map WorkflowGraphNodeLabel (WorkflowGraphNode' userid fileid)))
        let wgNodes = Map.map (\WGN'{..} -> (WGN{wgnStatus=wgn'Status}, wgn'Edges)) wgNodes'
        return WorkflowGraph{..}
      _ -> terror $ "WorkflowGraph parseJSON error: expected tag workflow, but got " <> fieldTag

instance (ToJSON userid, ToJSON fileid) => ToJSON (WorkflowGraphEdge userid fileid) where
  toJSON (WGE{..}) = JSON.object
    [ "actors" JSON..= Set.toList wgeActors
    , "target" JSON..= wgeTarget
    , "form"   JSON..= wgeForm
    ]
instance (Ord userid, Ord fileid, FromJSON userid, FromJSON fileid) => FromJSON (WorkflowGraphEdge userid fileid) where
  parseJSON = JSON.withObject "WorkflowGraphEdge" $ \o -> do
    wgeActors <- o JSON..: "actors"
    wgeTarget <- o JSON..: "target"
    wgeForm   <- o JSON..: "form"
    return WGE{..}

instance (ToJSON fileid, ToJSON userid) => ToJSON (WorkflowPayloadSpec fileid userid) where
  toJSON (WorkflowPayloadSpec WorkflowPayloadFieldText{..}) = JSON.object
    [ "tag"         JSON..= ("text" :: Text)
    , "label"       JSON..=  wepftLabel
    , "placeholder" JSON..=  wepftPlaceholder
    , "tooltip"     JSON..=  wepftTooltip
    , "default"     JSON..=  wepftDefault
    , "optional"    JSON..=  wepftOptional
    ]
  toJSON (WorkflowPayloadSpec WorkflowPayloadFieldNumber{..}) = JSON.object
    [ "tag"         JSON..= ("number" :: Text)
    , "label"       JSON..=  wepfnLabel
    , "placeholder" JSON..=  wepfnPlaceholder
    , "tooltip"     JSON..=  wepfnTooltip
    , "default"     JSON..=  wepfnDefault
    , "min"         JSON..=  wepfnMin
    , "max"         JSON..=  wepfnMax
    , "step"        JSON..=  wepfnStep
    , "optional"    JSON..=  wepfnOptional
    ]
  toJSON (WorkflowPayloadSpec WorkflowPayloadFieldBool{..}) = JSON.object
    [ "tag"         JSON..= ("bool" :: Text)
    , "label"       JSON..=  wepfbLabel
    , "tooltip"     JSON..=  wepfbTooltip
    , "default"     JSON..=  wepfbDefault
    ]
  toJSON (WorkflowPayloadSpec WorkflowPayloadFieldFile{..}) = JSON.object
    [ "tag"         JSON..= ("file" :: Text)
    , "label"       JSON..=  wepffLabel
    , "tooltip"     JSON..=  wepffTooltip
    , "default"     JSON..=  wepffDefault
    , "optional"    JSON..=  wepffOptional
    ]
  toJSON (WorkflowPayloadSpec WorkflowPayloadFieldUser{..}) = JSON.object
    [ "tag"         JSON..= ("user" :: Text)
    , "label"       JSON..=  wepfuLabel
    , "tooltip"     JSON..=  wepfuTooltip
    , "default"     JSON..=  wepfuDefault
    , "optional"    JSON..=  wepfuOptional
    ]
instance (FromJSON fileid, FromJSON userid) => FromJSON (WorkflowPayloadSpec fileid userid) where
  parseJSON = JSON.withObject "WorkflowPayloadSpec" $ \o -> do
    fieldTag <- (o JSON..: "tag" :: Parser Text)
    case fieldTag of
      "text" -> do
        wepftLabel       <-  o JSON..:  "label"
        wepftPlaceholder <-  o JSON..:  "placeholder"
        wepftTooltip     <-  o JSON..:? "tooltip"
        wepftDefault     <-  o JSON..:? "default"
        wepftOptional    <-  o JSON..:? "optional"
        return $ WorkflowPayloadSpec WorkflowPayloadFieldText{..}
      "number" -> do
        wepfnLabel       <-  o JSON..:  "label"
        wepfnPlaceholder <-  o JSON..:  "placeholder"
        wepfnTooltip     <-  o JSON..:? "tooltip"
        wepfnDefault     <- (o JSON..:? "default" :: Parser (Maybe Scientific))
        wepfnMin         <-  o JSON..:? "min"
        wepfnMax         <-  o JSON..:? "max"
        wepfnStep        <-  o JSON..:  "step"
        wepfnOptional    <-  o JSON..:? "optional"
        return $ WorkflowPayloadSpec WorkflowPayloadFieldNumber{..}
      "bool" -> do
        wepfbLabel       <-  o JSON..:  "label"
        wepfbTooltip     <-  o JSON..:? "tooltip"
        wepfbDefault     <- (o JSON..:? "default" :: Parser (Maybe Bool))
        return $ WorkflowPayloadSpec WorkflowPayloadFieldBool{..}
      "file" -> do
        wepffLabel       <-  o JSON..:  "label"
        wepffTooltip     <-  o JSON..:? "tooltip"
        wepffDefault     <- (o JSON..:? "default" :: Parser (Maybe fileid))
        wepffOptional    <-  o JSON..:? "optional"
        return $ WorkflowPayloadSpec WorkflowPayloadFieldFile{..}
      "user" -> do
        wepfuLabel       <-  o JSON..:  "label"
        wepfuTooltip     <-  o JSON..:? "tooltip"
        wepfuDefault     <- (o JSON..:? "default" :: Parser (Maybe userid))
        wepfuOptional    <-  o JSON..:? "optional"
        return $ WorkflowPayloadSpec WorkflowPayloadFieldUser{..}
      _ -> terror $ "WorkflowPayloadSpec parseJSON error: expected field tag (text|number|bool|file|user), but got " <> fieldTag

--instance ToJSON WorkflowGraphNode where
--  toJSON WGN{..} = JSON.object
--    [ "tag"    JSON..= ("node" :: Text)
--    , "status" JSON..= wgnStatus
--    ]
--instance FromJSON WorkflowGraphNode where
--  parseJSON = JSON.withObject "WorkflowGraphNode" $ \o -> do
--    fieldTag <- o JSON..: "tag"
--    case fieldTag of
--      "node" -> do
--        wgnStatus <- o JSON..: "status"
--        return WGN{..}
--      _ -> terror $ "WorkflowGraphNode parseJSON error: expected tag node, but got " <> fieldTag

deriveJSON defaultOptions
  { fieldLabelModifier = camelToPathPiece' 1
  } ''WorkflowGraphNodeStatus

instance (ToJSON userid, ToJSON fileid, Ord userid) => ToJSON (WorkflowGraphNode' userid fileid) where
  toJSON WGN'{..} = JSON.object
    [ "status" JSON..= wgn'Status
    , "edges"  JSON..= wgn'Edges
    ]
instance (FromJSON userid, FromJSON fileid, Ord userid, Ord fileid) => FromJSON (WorkflowGraphNode' userid fileid) where
  parseJSON = JSON.withObject "WorkflowGraphNode'" $ \o -> do
    wgn'Status <- o JSON..: "status"
    wgn'Edges  <- o JSON..: "edges"
    return WGN'{..}


testGraph :: WorkflowGraph Text Text
testGraph = WorkflowGraph $ Map.fromList [("node1", (WGN (WGNS "id" True (Just "someLabel")), Set.fromList [WGE (Set.fromList [WorkflowRoleUser "user-id", WorkflowRoleInitiator]) "node1" (Map.fromList [("sometext", impureNonNull $ Set.fromList [WorkflowPayloadSpec $ WorkflowPayloadFieldText "text-label" "text-placeholder" (Just "text-tooltip") (Just "text-default") Nothing]),("someuser", impureNonNull $ Set.fromList [WorkflowPayloadSpec $ WorkflowPayloadFieldUser "user-label" Nothing Nothing Nothing]),("someboolandnumber-opt", impureNonNull $ Set.fromList [WorkflowPayloadSpec $ WorkflowPayloadFieldBool "bool-label" Nothing (Just True), WorkflowPayloadSpec $ WorkflowPayloadFieldNumber "number-label" "number-placeholder" Nothing Nothing (Just 1) (Just 5) 0.01 (Just True)])])]))]

testGraphStr :: Data.ByteString.Lazy.Internal.ByteString
testGraphStr = "{\"tag\":\"workflow\",\"nodes\":{\"node1\":{\"status\":{\"ident\":\"status-ident\",\"finished\":true,\"label\":\"status-label\"},\"edges\":[{\"actors\":[{\"tag\":\"initiator\"}],\"form\":{\"some-number\":[{\"tag\":\"number\",\"step\":0.01,\"label\":\"number-label\",\"placeholder\":\"number-placeholder\"}]},\"target\":\"node1\"}]}}}"
--testGraph = WorkflowGraph $ Map.fromList [("node1", (WGN (WGNS "id" True (Just "someLabel")), Set.fromList [WGE (Set.fromList [WorkflowRoleUser "user-id", WorkflowRoleInitiator]) "node1" (Map.fromList [("sometext", impureNonNull $ Set.fromList [WorkflowPayloadSpec $ WorkflowPayloadFieldText "text-label" "text-placeholder" (Just "text-tooltip") (Just "text-default")]),("someuser", impureNonNull $ Set.fromList [WorkflowPayloadSpec $ WorkflowPayloadFieldUser "user-label" Nothing Nothing]),("somebool", impureNonNull $ Set.fromList [WorkflowPayloadSpec $ WorkflowPayloadFieldBool "bool-label" Nothing (Just True)])])]))]

--testPayload :: WorkflowPayload Text Text
testPayload = Map.fromList [("sometext" :: WorkflowPayloadLabel, (Seq.singleton (WFPText "text-label" "hello world!"), Just "actor-user-id" :: Maybe Text, UTCTime (ModifiedJulianDay 58946) 57250))]
