packages feed

casa-reoc-0.1.0.0: src/ReOC/Data/ApplicationForm.hs

{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall #-}
-- The checks of inheritance (inheritApplicationForm') have a constraint that their body does not use, by design.
{-# OPTIONS_GHC -Wno-redundant-constraints #-}

-- | The data type @ApplicationForm'@: the answers to CASA Form 101-02 that are not part of the operator, the operations manual or the training material, and the written signature of the declarant, if the form is to be signed. Each other document submitted takes a line of the box of question 30.
module ReOC.Data.ApplicationForm (
  ApplicationForm' (..),
  ApplicationForm'Like (..),
  lawNamesApplicationForm',
  ApplicationForm,
  UnfilledApplicationForm,
  mkApplicationForm,
  mkUnfilledApplicationForm,
  InheritApplicationForm',
  inheritApplicationForm',
) where

import Control.Lens (Optic, cloneLens, view)
import Data.Functor.Const (Const)
import Data.Text (Text)
import ReOC.Data.Declaration (Declaration, UnfilledDeclaration)
import ReOC.Data.PersonnelHistory (PersonnelHistory, UnfilledPersonnelHistory, mkUnfilledPersonnelHistory)
import ReOC.Data.PrimaryContact (PrimaryContact, UnfilledPrimaryContact)
import ReOC.Data.RegulatoryHistory (RegulatoryHistory, UnfilledRegulatoryHistory)
import ReOC.Data.WrittenSignature (UnfilledWrittenSignature, WrittenSignature)
import ReOC.Name.Declaration (DeclarationLike (..))
import ReOC.Name.OtherDocuments (OtherDocumentsLike (..))
import ReOC.Name.PersonnelHistory (PersonnelHistoryLike (..))
import ReOC.Name.PrimaryContact (PrimaryContactLike (..))
import ReOC.Name.ProceduresLibrary (ProceduresLibraryLike (..))
import ReOC.Name.RegulatoryHistory (RegulatoryHistoryLike (..))
import ReOC.Name.Signature (SignatureLike (..))
import ReOC.Primitive.AtMost (AtMost, atMostNone)
import ReOC.Primitive.FormText (FormLine)

-- | The answers to CASA Form 101-02 that are not part of the operator, the operations manual or the training material, and the written signature of the declarant, if the form is to be signed. Each other document submitted takes a line of the box of question 30. Its valid form is @ApplicationForm@, and its unfilled form @UnfilledApplicationForm@.
data ApplicationForm' a1 a2 a3 a4 a5 a6 a7 = ApplicationForm' a1 a2 a3 a4 a5 a6 a7
  deriving (Eq, Ord, Show)

-- | The name of the data type @ApplicationForm'@.
class ApplicationForm'Like p f x x' a1 a1' a2 a2' a3 a3' a4 a4' a5 a5' a6 a6' a7 a7' | x -> a1 a2 a3 a4 a5 a6 a7 where
  applicationForm' ::
    Optic p f x x' (ApplicationForm' a1 a2 a3 a4 a5 a6 a7) (ApplicationForm' a1' a2' a3' a4' a5' a6' a7')

-- | Identity
instance (x' ~ ApplicationForm' a1' a2' a3' a4' a5' a6' a7') => ApplicationForm'Like p f (ApplicationForm' a1 a2 a3 a4 a5 a6 a7) x' a1 a1' a2 a2' a3 a3' a4 a4' a5 a5' a6 a6' a7 a7' where
  applicationForm' = id

-- | Lens
instance (p ~ (->), Functor f, x' ~ ApplicationForm' a1' a2 a3 a4 a5 a6 a7) => PrimaryContactLike p f (ApplicationForm' a1 a2 a3 a4 a5 a6 a7) x' a1 a1' where
  primaryContact f (ApplicationForm' x1 x2 x3 x4 x5 x6 x7) = fmap (\x1' -> ApplicationForm' x1' x2 x3 x4 x5 x6 x7) (f x1)

-- | Lens
instance (p ~ (->), Functor f, x' ~ ApplicationForm' a1 a2' a3 a4 a5 a6 a7) => PersonnelHistoryLike p f (ApplicationForm' a1 a2 a3 a4 a5 a6 a7) x' a2 a2' where
  personnelHistory f (ApplicationForm' x1 x2 x3 x4 x5 x6 x7) = fmap (\x2' -> ApplicationForm' x1 x2' x3 x4 x5 x6 x7) (f x2)

-- | Lens
instance (p ~ (->), Functor f, x' ~ ApplicationForm' a1 a2 a3' a4 a5 a6 a7) => RegulatoryHistoryLike p f (ApplicationForm' a1 a2 a3 a4 a5 a6 a7) x' a3 a3' where
  regulatoryHistory f (ApplicationForm' x1 x2 x3 x4 x5 x6 x7) = fmap (\x3' -> ApplicationForm' x1 x2 x3' x4 x5 x6 x7) (f x3)

-- | Lens
instance (p ~ (->), Functor f, x' ~ ApplicationForm' a1 a2 a3 a4' a5 a6 a7) => ProceduresLibraryLike p f (ApplicationForm' a1 a2 a3 a4 a5 a6 a7) x' a4 a4' where
  proceduresLibrary f (ApplicationForm' x1 x2 x3 x4 x5 x6 x7) = fmap (\x4' -> ApplicationForm' x1 x2 x3 x4' x5 x6 x7) (f x4)

-- | Lens
instance (p ~ (->), Functor f, x' ~ ApplicationForm' a1 a2 a3 a4 a5' a6 a7) => OtherDocumentsLike p f (ApplicationForm' a1 a2 a3 a4 a5 a6 a7) x' a5 a5' where
  otherDocuments f (ApplicationForm' x1 x2 x3 x4 x5 x6 x7) = fmap (\x5' -> ApplicationForm' x1 x2 x3 x4 x5' x6 x7) (f x5)

-- | Lens
instance (p ~ (->), Functor f, x' ~ ApplicationForm' a1 a2 a3 a4 a5 a6' a7) => DeclarationLike p f (ApplicationForm' a1 a2 a3 a4 a5 a6 a7) x' a6 a6' where
  declaration f (ApplicationForm' x1 x2 x3 x4 x5 x6 x7) = fmap (\x6' -> ApplicationForm' x1 x2 x3 x4 x5 x6' x7) (f x6)

-- | Lens
instance (p ~ (->), Functor f, x' ~ ApplicationForm' a1 a2 a3 a4 a5 a6 a7') => SignatureLike p f (ApplicationForm' a1 a2 a3 a4 a5 a6 a7) x' a7 a7' where
  signature f (ApplicationForm' x1 x2 x3 x4 x5 x6 x7) = fmap (ApplicationForm' x1 x2 x3 x4 x5 x6) (f x7)

{- | Rebuilds a value from the name of each field or constructor.

Laws:

> lawNamesApplicationForm' == id
-}
lawNamesApplicationForm' :: ApplicationForm' a1 a2 a3 a4 a5 a6 a7 -> ApplicationForm' a1 a2 a3 a4 a5 a6 a7
lawNamesApplicationForm' s =
  ApplicationForm'
    (view (cloneLens primaryContact) s)
    (view (cloneLens personnelHistory) s)
    (view (cloneLens regulatoryHistory) s)
    (view (cloneLens proceduresLibrary) s)
    (view (cloneLens otherDocuments) s)
    (view (cloneLens declaration) s)
    (view (cloneLens signature) s)

-- | A valid @ApplicationForm'@.
type ApplicationForm = ApplicationForm' PrimaryContact PersonnelHistory RegulatoryHistory Bool (AtMost 6 FormLine) Declaration (Maybe WrittenSignature)

-- | An unfilled @ApplicationForm'@: each field holds what has been entered, if anything, to be checked by @fillApplicationForm@.
type UnfilledApplicationForm = ApplicationForm' (Maybe UnfilledPrimaryContact) UnfilledPersonnelHistory (Maybe UnfilledRegulatoryHistory) (Maybe Bool) [Text] (Maybe UnfilledDeclaration) (Maybe UnfilledWrittenSignature)

-- | Builds a valid @ApplicationForm'@ with every @Maybe@ field @Nothing@ and every list (or @AtMost@) field empty.
mkApplicationForm :: PrimaryContact -> PersonnelHistory -> RegulatoryHistory -> Bool -> Declaration -> ApplicationForm
mkApplicationForm x1 x2 x3 x4 x5 = ApplicationForm' x1 x2 x3 x4 atMostNone x5 Nothing

-- | An unfilled @ApplicationForm'@ with nothing entered.
mkUnfilledApplicationForm :: UnfilledApplicationForm
mkUnfilledApplicationForm =
  ApplicationForm'
    Nothing
    mkUnfilledPersonnelHistory
    Nothing
    Nothing
    []
    Nothing
    Nothing

-- | The classes that a data type holding @ApplicationForm'@ in one field, or in one or more constructors, inherits.
type InheritApplicationForm' s a1 a2 a3 a4 a5 a6 a7 =
  ( ApplicationForm'Like (->) (Const ()) s s a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7
  , PrimaryContactLike (->) (Const ()) s s a1 a1
  , PersonnelHistoryLike (->) (Const ()) s s a2 a2
  , RegulatoryHistoryLike (->) (Const ()) s s a3 a3
  , ProceduresLibraryLike (->) (Const ()) s s a4 a4
  , OtherDocumentsLike (->) (Const ()) s s a5 a5
  , DeclarationLike (->) (Const ()) s s a6 a6
  , SignatureLike (->) (Const ()) s s a7 a7
  )

-- | Checks that a data type inherits every class of @InheritApplicationForm'@.
inheritApplicationForm' :: (InheritApplicationForm' s a1 a2 a3 a4 a5 a6 a7) => proxy s -> ()
inheritApplicationForm' _ = ()