{- |
Module: Pollock.Documentation.Metadata
Copyright: (c) Trevis Elser 2023
License: MIT
Maintainer: trevis@flipstone.com
Stability: experimental
Portability: portable
-}
module Pollock.Documentation.Metadata
  ( Metadata (..)
  , emptyMetadata
  , metaAppend
  , metadataHasSinceVersion
  ) where

import Control.Applicative ((<|>))

newtype Metadata = Metadata
  { Metadata -> Maybe SinceVersion
version :: Maybe SinceVersion
  }

emptyMetadata :: Metadata
emptyMetadata :: Metadata
emptyMetadata =
  Metadata
    { version :: Maybe SinceVersion
version = Maybe SinceVersion
forall a. Maybe a
Nothing
    }

-- | This is not a monoidal append, it uses '<|>' for the 'version'.
metaAppend :: Metadata -> Metadata -> Metadata
metaAppend :: Metadata -> Metadata -> Metadata
metaAppend (Metadata Maybe SinceVersion
v1) (Metadata Maybe SinceVersion
v2) = Maybe SinceVersion -> Metadata
Metadata (Maybe SinceVersion
v1 Maybe SinceVersion -> Maybe SinceVersion -> Maybe SinceVersion
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe SinceVersion
v2)

metadataHasSinceVersion :: Metadata -> Bool
metadataHasSinceVersion :: Metadata -> Bool
metadataHasSinceVersion (Metadata Maybe SinceVersion
Nothing) = Bool
False
metadataHasSinceVersion (Metadata (Just SinceVersion
vs)) = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ SinceVersion -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null SinceVersion
vs

type SinceVersion = [Int]