{- |
Module:  Pollock.Documentation.ExportItem
Copyright: (c) Trevis Elser 2023
License:  MIT

Maintainer: trevis@flipstone.com
Stability: experimental
Portability: portable
-}
module Pollock.Documentation.ExportItem
  ( ExportItem (..)
  , mkExportDoc
  , ExportDecl (..)
  , exportItemHasSinceVersion
  , exportItemHasCodeBlock
  , exportItemHasExample
  , exportItemHasProperty
  , exportItemHasWarning
  ) where

import Pollock.Documentation.Doc
  ( docHasCodeBlock
  , docHasExamples
  , docHasProperty
  , docHasWarning
  )
import Pollock.Documentation.DocumentationForDecl
  ( DocumentationForDecl
  , documentationDoc
  )
import Pollock.Documentation.Metadata (metadataHasSinceVersion)
import Pollock.Documentation.MetadataAndDoc (MetaAndDoc, doc, meta)

data ExportItem
  = ExportItemDecl {-# UNPACK #-} !ExportDecl
  | ExportItemDoc !MetaAndDoc

mkExportDoc :: MetaAndDoc -> ExportItem
mkExportDoc :: MetaAndDoc -> ExportItem
mkExportDoc = MetaAndDoc -> ExportItem
ExportItemDoc

newtype ExportDecl = ExportDecl
  { ExportDecl -> DocumentationForDecl
expItemMbDoc :: DocumentationForDecl
  }

exportItemHasSinceVersion :: ExportItem -> Bool
exportItemHasSinceVersion :: ExportItem -> Bool
exportItemHasSinceVersion (ExportItemDoc MetaAndDoc
md) =
  Metadata -> Bool
metadataHasSinceVersion (Metadata -> Bool) -> Metadata -> Bool
forall a b. (a -> b) -> a -> b
$ MetaAndDoc -> Metadata
meta MetaAndDoc
md
exportItemHasSinceVersion (ExportItemDecl ExportDecl
decl) =
  case DocumentationForDecl -> Maybe MetaAndDoc
documentationDoc (DocumentationForDecl -> Maybe MetaAndDoc)
-> DocumentationForDecl -> Maybe MetaAndDoc
forall a b. (a -> b) -> a -> b
$ ExportDecl -> DocumentationForDecl
expItemMbDoc ExportDecl
decl of
    Maybe MetaAndDoc
Nothing -> Bool
False
    Just MetaAndDoc
md -> Metadata -> Bool
metadataHasSinceVersion (Metadata -> Bool) -> Metadata -> Bool
forall a b. (a -> b) -> a -> b
$ MetaAndDoc -> Metadata
meta MetaAndDoc
md

exportItemHasWarning :: ExportItem -> Bool
exportItemHasWarning :: ExportItem -> Bool
exportItemHasWarning (ExportItemDoc MetaAndDoc
md) =
  Doc -> Bool
docHasWarning (Doc -> Bool) -> Doc -> Bool
forall a b. (a -> b) -> a -> b
$ MetaAndDoc -> Doc
doc MetaAndDoc
md
exportItemHasWarning (ExportItemDecl ExportDecl
decl) =
  case DocumentationForDecl -> Maybe MetaAndDoc
documentationDoc (DocumentationForDecl -> Maybe MetaAndDoc)
-> DocumentationForDecl -> Maybe MetaAndDoc
forall a b. (a -> b) -> a -> b
$ ExportDecl -> DocumentationForDecl
expItemMbDoc ExportDecl
decl of
    Maybe MetaAndDoc
Nothing -> Bool
False
    Just MetaAndDoc
md -> Doc -> Bool
docHasWarning (Doc -> Bool) -> Doc -> Bool
forall a b. (a -> b) -> a -> b
$ MetaAndDoc -> Doc
doc MetaAndDoc
md

exportItemHasProperty :: ExportItem -> Bool
exportItemHasProperty :: ExportItem -> Bool
exportItemHasProperty (ExportItemDoc MetaAndDoc
md) =
  Doc -> Bool
docHasProperty (Doc -> Bool) -> Doc -> Bool
forall a b. (a -> b) -> a -> b
$ MetaAndDoc -> Doc
doc MetaAndDoc
md
exportItemHasProperty (ExportItemDecl ExportDecl
decl) =
  case DocumentationForDecl -> Maybe MetaAndDoc
documentationDoc (DocumentationForDecl -> Maybe MetaAndDoc)
-> DocumentationForDecl -> Maybe MetaAndDoc
forall a b. (a -> b) -> a -> b
$ ExportDecl -> DocumentationForDecl
expItemMbDoc ExportDecl
decl of
    Maybe MetaAndDoc
Nothing -> Bool
False
    Just MetaAndDoc
md -> Doc -> Bool
docHasProperty (Doc -> Bool) -> Doc -> Bool
forall a b. (a -> b) -> a -> b
$ MetaAndDoc -> Doc
doc MetaAndDoc
md

exportItemHasExample :: ExportItem -> Bool
exportItemHasExample :: ExportItem -> Bool
exportItemHasExample (ExportItemDoc MetaAndDoc
md) =
  Doc -> Bool
docHasExamples (Doc -> Bool) -> Doc -> Bool
forall a b. (a -> b) -> a -> b
$ MetaAndDoc -> Doc
doc MetaAndDoc
md
exportItemHasExample (ExportItemDecl ExportDecl
decl) =
  case DocumentationForDecl -> Maybe MetaAndDoc
documentationDoc (DocumentationForDecl -> Maybe MetaAndDoc)
-> DocumentationForDecl -> Maybe MetaAndDoc
forall a b. (a -> b) -> a -> b
$ ExportDecl -> DocumentationForDecl
expItemMbDoc ExportDecl
decl of
    Maybe MetaAndDoc
Nothing -> Bool
False
    Just MetaAndDoc
md -> Doc -> Bool
docHasExamples (Doc -> Bool) -> Doc -> Bool
forall a b. (a -> b) -> a -> b
$ MetaAndDoc -> Doc
doc MetaAndDoc
md

exportItemHasCodeBlock :: ExportItem -> Bool
exportItemHasCodeBlock :: ExportItem -> Bool
exportItemHasCodeBlock (ExportItemDoc MetaAndDoc
md) =
  Doc -> Bool
docHasCodeBlock (Doc -> Bool) -> Doc -> Bool
forall a b. (a -> b) -> a -> b
$ MetaAndDoc -> Doc
doc MetaAndDoc
md
exportItemHasCodeBlock (ExportItemDecl ExportDecl
decl) =
  case DocumentationForDecl -> Maybe MetaAndDoc
documentationDoc (DocumentationForDecl -> Maybe MetaAndDoc)
-> DocumentationForDecl -> Maybe MetaAndDoc
forall a b. (a -> b) -> a -> b
$ ExportDecl -> DocumentationForDecl
expItemMbDoc ExportDecl
decl of
    Maybe MetaAndDoc
Nothing -> Bool
False
    Just MetaAndDoc
md -> Doc -> Bool
docHasCodeBlock (Doc -> Bool) -> Doc -> Bool
forall a b. (a -> b) -> a -> b
$ MetaAndDoc -> Doc
doc MetaAndDoc
md