packages feed

casa-reoc-0.1.0.0: examples/src/ReOC/Example/Draft.hs

{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall #-}

{- | An application that has only been started: the company's name, an ABN
with a typing error, and a CEO's name. Filling it in gives every reason it
is not yet valid.

>>> import qualified Data.Text as Text
>>> import qualified Data.Text.IO as Text
>>> mapM_ Text.putStrLn (take 3 (Text.lines draftReport))
operator › company › ABN: “15 092 285 143” is not an ABN: 11 digits with valid check digits (The company’s Australian business number (ABN).)
operator › company › ARN: not filled in (The company’s CASA aviation reference number (ARN).)
operator › company › registered office › street address: not filled in (The lines of the street address, such as unit and street; one or more.)
-}
module ReOC.Example.Draft (
  draftInput,
  draft,
  draftReport,
) where

import Control.Lens ((&), (?~))
import Data.List.NonEmpty (NonEmpty)
import Data.Text (Text)
import ReOC.Fill (fillReOC)
import ReOC.Model
import ReOC.Render.Error (renderReOCErrors)

-- | An application that has only been started.
draftInput :: UnfilledReOC
draftInput =
  mkUnfilledReOC
    & operator . company . companyName ?~ "Banksia Point Aerial Media"
    & operator . company . abn ?~ "15 092 285 143"
    & operator . keyPersonnel . chiefExecutive . nominee . person . fullName ?~ "Mei-Ling Hartley"

-- | The reasons that the draft is not yet valid.
draft :: Either (NonEmpty ReOCError) ReOC
draft =
  fillReOC draftInput

-- | The reasons that the draft is not yet valid, one to a line.
draftReport :: Text
draftReport =
  either renderReOCErrors (const "") draft