packages feed

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

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

-- | The data type @InvalidValue@: a value entered in an unfilled form that its field does not accept.
module ReOC.Data.InvalidValue (
  InvalidValue (..),
  InvalidValueLike (..),
  lawNamesInvalidValue,
  InheritInvalidValue,
  inheritInvalidValue,
) where

import Control.Lens (Choice, Optic, prism', review)
import Data.Functor.Const (Const)
import Data.Text (Text)
import Numeric.Natural (Natural)
import ReOC.Name.InvalidABN (InvalidABNLike (..))
import ReOC.Name.InvalidARN (InvalidARNLike (..))
import ReOC.Name.InvalidEmailAddress (InvalidEmailAddressLike (..))
import ReOC.Name.InvalidFormText (InvalidFormTextLike (..))
import ReOC.Name.InvalidGrossWeight (InvalidGrossWeightLike (..))
import ReOC.Name.InvalidPassMark (InvalidPassMarkLike (..))
import ReOC.Name.InvalidPercentage (InvalidPercentageLike (..))
import ReOC.Name.InvalidPhoneNumber (InvalidPhoneNumberLike (..))
import ReOC.Name.InvalidPositive (InvalidPositiveLike (..))
import ReOC.Name.InvalidPostcode (InvalidPostcodeLike (..))
import ReOC.Name.InvalidReviewMonths (InvalidReviewMonthsLike (..))
import ReOC.Name.InvalidText1 (InvalidText1Like (..))

-- | A value entered in an unfilled form that its field does not accept.
data InvalidValue
  = InvalidText1 Text
  | InvalidFormText Text
  | InvalidABN Text
  | InvalidARN Text
  | InvalidEmailAddress Text
  | InvalidPhoneNumber Text
  | InvalidPostcode Text
  | InvalidPositive Natural
  | InvalidPercentage Natural
  | InvalidGrossWeight Natural
  | InvalidReviewMonths Natural
  | InvalidPassMark Natural
  deriving (Eq, Ord, Show)

-- | The name of the data type @InvalidValue@.
class InvalidValueLike p f x x' where
  invalidValue ::
    Optic p f x x' InvalidValue InvalidValue

-- | Identity
instance (x' ~ InvalidValue) => InvalidValueLike p f InvalidValue x' where
  invalidValue = id

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidText1Like p f InvalidValue x' where
  invalidText1 = prism' InvalidText1 (\case InvalidText1 x -> Just x; InvalidFormText _ -> Nothing; InvalidABN _ -> Nothing; InvalidARN _ -> Nothing; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber _ -> Nothing; InvalidPostcode _ -> Nothing; InvalidPositive _ -> Nothing; InvalidPercentage _ -> Nothing; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths _ -> Nothing; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidFormTextLike p f InvalidValue x' where
  invalidFormText = prism' InvalidFormText (\case InvalidText1 _ -> Nothing; InvalidFormText x -> Just x; InvalidABN _ -> Nothing; InvalidARN _ -> Nothing; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber _ -> Nothing; InvalidPostcode _ -> Nothing; InvalidPositive _ -> Nothing; InvalidPercentage _ -> Nothing; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths _ -> Nothing; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidABNLike p f InvalidValue x' where
  invalidABN = prism' InvalidABN (\case InvalidText1 _ -> Nothing; InvalidFormText _ -> Nothing; InvalidABN x -> Just x; InvalidARN _ -> Nothing; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber _ -> Nothing; InvalidPostcode _ -> Nothing; InvalidPositive _ -> Nothing; InvalidPercentage _ -> Nothing; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths _ -> Nothing; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidARNLike p f InvalidValue x' where
  invalidARN = prism' InvalidARN (\case InvalidText1 _ -> Nothing; InvalidFormText _ -> Nothing; InvalidABN _ -> Nothing; InvalidARN x -> Just x; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber _ -> Nothing; InvalidPostcode _ -> Nothing; InvalidPositive _ -> Nothing; InvalidPercentage _ -> Nothing; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths _ -> Nothing; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidEmailAddressLike p f InvalidValue x' where
  invalidEmailAddress = prism' InvalidEmailAddress (\case InvalidText1 _ -> Nothing; InvalidFormText _ -> Nothing; InvalidABN _ -> Nothing; InvalidARN _ -> Nothing; InvalidEmailAddress x -> Just x; InvalidPhoneNumber _ -> Nothing; InvalidPostcode _ -> Nothing; InvalidPositive _ -> Nothing; InvalidPercentage _ -> Nothing; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths _ -> Nothing; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidPhoneNumberLike p f InvalidValue x' where
  invalidPhoneNumber = prism' InvalidPhoneNumber (\case InvalidText1 _ -> Nothing; InvalidFormText _ -> Nothing; InvalidABN _ -> Nothing; InvalidARN _ -> Nothing; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber x -> Just x; InvalidPostcode _ -> Nothing; InvalidPositive _ -> Nothing; InvalidPercentage _ -> Nothing; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths _ -> Nothing; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidPostcodeLike p f InvalidValue x' where
  invalidPostcode = prism' InvalidPostcode (\case InvalidText1 _ -> Nothing; InvalidFormText _ -> Nothing; InvalidABN _ -> Nothing; InvalidARN _ -> Nothing; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber _ -> Nothing; InvalidPostcode x -> Just x; InvalidPositive _ -> Nothing; InvalidPercentage _ -> Nothing; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths _ -> Nothing; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidPositiveLike p f InvalidValue x' where
  invalidPositive = prism' InvalidPositive (\case InvalidText1 _ -> Nothing; InvalidFormText _ -> Nothing; InvalidABN _ -> Nothing; InvalidARN _ -> Nothing; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber _ -> Nothing; InvalidPostcode _ -> Nothing; InvalidPositive x -> Just x; InvalidPercentage _ -> Nothing; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths _ -> Nothing; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidPercentageLike p f InvalidValue x' where
  invalidPercentage = prism' InvalidPercentage (\case InvalidText1 _ -> Nothing; InvalidFormText _ -> Nothing; InvalidABN _ -> Nothing; InvalidARN _ -> Nothing; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber _ -> Nothing; InvalidPostcode _ -> Nothing; InvalidPositive _ -> Nothing; InvalidPercentage x -> Just x; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths _ -> Nothing; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidGrossWeightLike p f InvalidValue x' where
  invalidGrossWeight = prism' InvalidGrossWeight (\case InvalidText1 _ -> Nothing; InvalidFormText _ -> Nothing; InvalidABN _ -> Nothing; InvalidARN _ -> Nothing; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber _ -> Nothing; InvalidPostcode _ -> Nothing; InvalidPositive _ -> Nothing; InvalidPercentage _ -> Nothing; InvalidGrossWeight x -> Just x; InvalidReviewMonths _ -> Nothing; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidReviewMonthsLike p f InvalidValue x' where
  invalidReviewMonths = prism' InvalidReviewMonths (\case InvalidText1 _ -> Nothing; InvalidFormText _ -> Nothing; InvalidABN _ -> Nothing; InvalidARN _ -> Nothing; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber _ -> Nothing; InvalidPostcode _ -> Nothing; InvalidPositive _ -> Nothing; InvalidPercentage _ -> Nothing; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths x -> Just x; InvalidPassMark _ -> Nothing)

-- | Prism
instance (Choice p, Applicative f, x' ~ InvalidValue) => InvalidPassMarkLike p f InvalidValue x' where
  invalidPassMark = prism' InvalidPassMark (\case InvalidText1 _ -> Nothing; InvalidFormText _ -> Nothing; InvalidABN _ -> Nothing; InvalidARN _ -> Nothing; InvalidEmailAddress _ -> Nothing; InvalidPhoneNumber _ -> Nothing; InvalidPostcode _ -> Nothing; InvalidPositive _ -> Nothing; InvalidPercentage _ -> Nothing; InvalidGrossWeight _ -> Nothing; InvalidReviewMonths _ -> Nothing; InvalidPassMark x -> Just x)

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

Laws:

> lawNamesInvalidValue == id
-}
lawNamesInvalidValue :: InvalidValue -> InvalidValue
lawNamesInvalidValue = \case
  InvalidText1 x -> review invalidText1 x
  InvalidFormText x -> review invalidFormText x
  InvalidABN x -> review invalidABN x
  InvalidARN x -> review invalidARN x
  InvalidEmailAddress x -> review invalidEmailAddress x
  InvalidPhoneNumber x -> review invalidPhoneNumber x
  InvalidPostcode x -> review invalidPostcode x
  InvalidPositive x -> review invalidPositive x
  InvalidPercentage x -> review invalidPercentage x
  InvalidGrossWeight x -> review invalidGrossWeight x
  InvalidReviewMonths x -> review invalidReviewMonths x
  InvalidPassMark x -> review invalidPassMark x

-- | The classes that a data type holding @InvalidValue@ in one field, or in one or more constructors, inherits.
type InheritInvalidValue s =
  ( InvalidValueLike (->) (Const ()) s s
  , InvalidText1Like (->) (Const ()) s s
  , InvalidFormTextLike (->) (Const ()) s s
  , InvalidABNLike (->) (Const ()) s s
  , InvalidARNLike (->) (Const ()) s s
  , InvalidEmailAddressLike (->) (Const ()) s s
  , InvalidPhoneNumberLike (->) (Const ()) s s
  , InvalidPostcodeLike (->) (Const ()) s s
  , InvalidPositiveLike (->) (Const ()) s s
  , InvalidPercentageLike (->) (Const ()) s s
  , InvalidGrossWeightLike (->) (Const ()) s s
  , InvalidReviewMonthsLike (->) (Const ()) s s
  , InvalidPassMarkLike (->) (Const ()) s s
  )

-- | Checks that a data type inherits every class of @InheritInvalidValue@.
inheritInvalidValue :: (InheritInvalidValue s) => proxy s -> ()
inheritInvalidValue _ = ()