module Data.Icao.SupplementaryInformation
(
PersonsOnBoard
, Transmitter(..)
, SurvivalEquipment(..)
, LifeJacket(..)
, Dinghies(number, totalCapacity, covered, colour)
, SupplementaryInformation(..)
, emptySupplementaryInformation
, withFuelEndurance
, withPersonsOnBoard
, withAvailableTransmitters
, withSurvivalEquipments
, withAircraftDescription
, withLifeJackets
, withDinghies
, withOtherRemarks
, withPilotInCommand
, mkPersonsOnBoard
, mkDinghies
) where
import Control.Monad.Fail
import Data.Char (isUpper)
import Data.Icao.Lang
import Data.Icao.Time
import Data.Maybe ()
import Prelude hiding (fail)
newtype PersonsOnBoard =
PersonsOnBoard Int
deriving (Eq, Show)
data Transmitter
= UHF
| VHF
| ELT
deriving (Bounded, Enum, Eq, Read, Show)
data SurvivalEquipment
= Polar
| Desert
| Maritime
| Jungle
deriving (Bounded, Enum, Eq, Read, Show)
data LifeJacket
= WithLight
| WithFluorescein
| WithRadioUHF
| WithRadioVHF
deriving (Bounded, Enum, Eq, Read, Show)
data Dinghies = Dinghies
{ number :: Maybe Int
, totalCapacity :: Maybe Int
, covered :: Bool
, colour :: Maybe String
} deriving (Eq, Show)
data SupplementaryInformation = SupplementaryInformation
{ fuelEndurance :: Maybe Hhmm
, personsOnBoard :: Maybe PersonsOnBoard
, availableTransmitters :: [Transmitter]
, survivalEquipments :: [SurvivalEquipment]
, lifeJackets :: [LifeJacket]
, dinghies :: Dinghies
, aircraftDescription :: Maybe FreeText
, otherRemarks :: Maybe FreeText
, pilotInCommand :: Maybe FreeText
} deriving (Eq, Show)
emptySupplementaryInformation :: SupplementaryInformation
emptySupplementaryInformation =
SupplementaryInformation
Nothing
Nothing
[]
[]
[]
(Dinghies Nothing Nothing False Nothing)
Nothing
Nothing
Nothing
withFuelEndurance :: Hhmm -> SupplementaryInformation -> SupplementaryInformation
withFuelEndurance fe si = si {fuelEndurance = Just fe}
withPersonsOnBoard :: PersonsOnBoard -> SupplementaryInformation -> SupplementaryInformation
withPersonsOnBoard n si = si {personsOnBoard = Just n}
withAvailableTransmitters :: [Transmitter] -> SupplementaryInformation -> SupplementaryInformation
withAvailableTransmitters t si = si {availableTransmitters = t}
withSurvivalEquipments :: [SurvivalEquipment]
-> SupplementaryInformation
-> SupplementaryInformation
withSurvivalEquipments s si = si {survivalEquipments = s}
withAircraftDescription :: FreeText -> SupplementaryInformation -> SupplementaryInformation
withAircraftDescription d si = si {aircraftDescription = Just d}
withPilotInCommand :: FreeText -> SupplementaryInformation -> SupplementaryInformation
withPilotInCommand p si = si {pilotInCommand = Just p}
withDinghies :: Dinghies -> SupplementaryInformation -> SupplementaryInformation
withDinghies d si = si {dinghies = d}
withLifeJackets :: [LifeJacket] -> SupplementaryInformation -> SupplementaryInformation
withLifeJackets l si = si {lifeJackets = l}
withOtherRemarks :: FreeText -> SupplementaryInformation -> SupplementaryInformation
withOtherRemarks r si = si {pilotInCommand = Just r}
mkPersonsOnBoard
:: (MonadFail m)
=> Int -> m PersonsOnBoard
mkPersonsOnBoard n
| n < 1 || n > 999 = fail ("invalid persons on board=" ++ show n)
| otherwise = return (PersonsOnBoard n)
mkDinghies
:: (MonadFail m)
=> Maybe Int -> Maybe Int -> Bool -> Maybe String -> m Dinghies
mkDinghies nb cap cov col
| maybe False (< 0) nb || maybe False (> 99) nb =
fail ("invalid number of dinghies=" ++ show nb)
| maybe False (< 0) cap || maybe False (> 999) cap =
fail ("invalid total capacity of dinghies=" ++ show cap)
| maybe False (not . all isUpper) col = fail ("invalid dinghies color=" ++ show col)
| otherwise = return (Dinghies nb cap cov col)