casa-reoc-0.1.0.0: src/ReOC/Aircraft.hs
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall #-}
{- | The RPA of a ReOC: the types the operator operates, and the training RPA
of its RePL training courses, which both documents list together.
-}
module ReOC.Aircraft (
rpaName,
rpaMakeAndModel,
operatedTypes,
rpaTypes,
heaviestGrams,
) where
import Control.Lens (cloneLens, view)
import Data.Foldable (toList)
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NonEmpty
import Data.Text (Text)
import Numeric.Natural (Natural)
import ReOC.Model
-- | The short name of a type of RPA, such as @DJI Mavic 3 Pro@.
rpaName :: RPAType -> Text
rpaName =
formTextText . view (cloneLens shortName)
-- | The manufacturer and model of a type of RPA, such as @DJI Mavic 3 Pro@.
rpaMakeAndModel :: RPAType -> Text
rpaMakeAndModel t =
text1Text (view (cloneLens rpaMake) t) <> " " <> text1Text (view (cloneLens rpaModel) t)
{- | Every type of RPA of a ReOC with its RPA: the operator's fleet, then the
training RPA of each RePL training course, each once.
-}
operatedTypes :: ReOC -> NonEmpty OperatedType
operatedTypes r =
let fleet' = someNonEmpty (view (cloneLens (operator . fleet)) r)
training =
maybe [] (map (view (cloneLens trainingRPA)) . toList . view (cloneLens trainingCourses)) (view (cloneLens maybeTrainingMaterial) r)
in NonEmpty.nub (NonEmpty.appendList fleet' training)
-- | Every type of RPA of a ReOC, each once.
rpaTypes :: ReOC -> NonEmpty RPAType
rpaTypes =
NonEmpty.nub . fmap (view (cloneLens rpaType)) . operatedTypes
-- | The maximum gross weight of the heaviest type of RPA of a ReOC, in grams.
heaviestGrams :: ReOC -> Natural
heaviestGrams =
maximum . fmap (grossWeightGrams . view (cloneLens maximumGrossWeight)) . rpaTypes