-------------------------------------------------------------------------------
-- |
-- Module       : Generator.Printer.Util
-- Copyright    : (c) 2016 Michael Carpenter
-- License      : BSD3
-- Maintainer   : Michael Carpenter <oldmanmike.dev@gmail.com>
-- Stability    : experimental
-- Portability  : portable
--
-------------------------------------------------------------------------------
module Generator.Printer.Util
  ( docFieldNames
  , docFieldTypes
  , docDataTypeName
  ) where

import qualified  Data.Text.Lazy as TL
import            Generator.Printer.Types
import            Generator.Types
import            Text.PrettyPrint.Leijen.Text


docFieldNames :: Maybe [Field] -> Doc
docFieldNames maybeFields =
    case maybeFields of
      Just fields -> hsep (fmap (text . fieldName) fields)
      Nothing     -> empty


docFieldTypes :: Maybe [Field] -> Doc
docFieldTypes maybeFields =
    case maybeFields of
      Just fields -> hsep (fmap (docFieldType . fieldType) fields)
      Nothing   -> empty


docDataTypeName :: PacketDirection -> ProtocolState -> Doc
docDataTypeName d s = string (TL.pack (show d ++ show s ++ "Packet"))
