{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}

module Data.Aviation.WB.Arm.ArmRangeLower(
  ArmRangeLower
, HasArmRangeLower(..)
, HasArmRangeLowers(..)
, SetArmRangeLower(..)
, HasArmRangeLower0(..)
) where

import Control.Category((.))
import Control.Lens(Lens', Traversal', Setter', makeClassy, iso)
import Data.Aviation.Units(Inches(inches), Centimetres(centimetres), Thouinches(thouinches))
import Data.Eq(Eq)
import Data.Maybe(Maybe)
import Data.Monoid(Monoid(mempty, mappend))
import Data.Ord(Ord)
import Data.Ratio((%))
import Data.Semigroup(Semigroup((<>)))
import Numeric.Lens(dividing, multiplying)
import Prelude(Show, Rational, (+))

newtype ArmRangeLower =
  ArmRangeLower
    Rational
  deriving (ArmRangeLower -> ArmRangeLower -> Bool
(ArmRangeLower -> ArmRangeLower -> Bool)
-> (ArmRangeLower -> ArmRangeLower -> Bool) -> Eq ArmRangeLower
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArmRangeLower -> ArmRangeLower -> Bool
$c/= :: ArmRangeLower -> ArmRangeLower -> Bool
== :: ArmRangeLower -> ArmRangeLower -> Bool
$c== :: ArmRangeLower -> ArmRangeLower -> Bool
Eq, Eq ArmRangeLower
Eq ArmRangeLower
-> (ArmRangeLower -> ArmRangeLower -> Ordering)
-> (ArmRangeLower -> ArmRangeLower -> Bool)
-> (ArmRangeLower -> ArmRangeLower -> Bool)
-> (ArmRangeLower -> ArmRangeLower -> Bool)
-> (ArmRangeLower -> ArmRangeLower -> Bool)
-> (ArmRangeLower -> ArmRangeLower -> ArmRangeLower)
-> (ArmRangeLower -> ArmRangeLower -> ArmRangeLower)
-> Ord ArmRangeLower
ArmRangeLower -> ArmRangeLower -> Bool
ArmRangeLower -> ArmRangeLower -> Ordering
ArmRangeLower -> ArmRangeLower -> ArmRangeLower
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ArmRangeLower -> ArmRangeLower -> ArmRangeLower
$cmin :: ArmRangeLower -> ArmRangeLower -> ArmRangeLower
max :: ArmRangeLower -> ArmRangeLower -> ArmRangeLower
$cmax :: ArmRangeLower -> ArmRangeLower -> ArmRangeLower
>= :: ArmRangeLower -> ArmRangeLower -> Bool
$c>= :: ArmRangeLower -> ArmRangeLower -> Bool
> :: ArmRangeLower -> ArmRangeLower -> Bool
$c> :: ArmRangeLower -> ArmRangeLower -> Bool
<= :: ArmRangeLower -> ArmRangeLower -> Bool
$c<= :: ArmRangeLower -> ArmRangeLower -> Bool
< :: ArmRangeLower -> ArmRangeLower -> Bool
$c< :: ArmRangeLower -> ArmRangeLower -> Bool
compare :: ArmRangeLower -> ArmRangeLower -> Ordering
$ccompare :: ArmRangeLower -> ArmRangeLower -> Ordering
$cp1Ord :: Eq ArmRangeLower
Ord, Int -> ArmRangeLower -> ShowS
[ArmRangeLower] -> ShowS
ArmRangeLower -> String
(Int -> ArmRangeLower -> ShowS)
-> (ArmRangeLower -> String)
-> ([ArmRangeLower] -> ShowS)
-> Show ArmRangeLower
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ArmRangeLower] -> ShowS
$cshowList :: [ArmRangeLower] -> ShowS
show :: ArmRangeLower -> String
$cshow :: ArmRangeLower -> String
showsPrec :: Int -> ArmRangeLower -> ShowS
$cshowsPrec :: Int -> ArmRangeLower -> ShowS
Show)

makeClassy ''ArmRangeLower

class HasArmRangeLowers a where
  armRangeLowers ::
    Traversal'
      a
      ArmRangeLower

instance HasArmRangeLowers ArmRangeLower where
  armRangeLowers :: (ArmRangeLower -> f ArmRangeLower)
-> ArmRangeLower -> f ArmRangeLower
armRangeLowers =
    (ArmRangeLower -> f ArmRangeLower)
-> ArmRangeLower -> f ArmRangeLower
forall c. HasArmRangeLower c => Lens' c ArmRangeLower
armRangeLower

class SetArmRangeLower a where
  setArmRangeLower ::
    Setter'
      a
      ArmRangeLower

instance SetArmRangeLower ArmRangeLower where
  setArmRangeLower :: (ArmRangeLower -> f ArmRangeLower)
-> ArmRangeLower -> f ArmRangeLower
setArmRangeLower =
    (ArmRangeLower -> f ArmRangeLower)
-> ArmRangeLower -> f ArmRangeLower
forall c. HasArmRangeLower c => Lens' c ArmRangeLower
armRangeLower

class HasArmRangeLower0 a where
  armRangeLower0 ::
    Lens'
      a
      (Maybe ArmRangeLower)

instance Inches ArmRangeLower where
  inches :: p ArmRangeLower (f ArmRangeLower) -> p Rational (f Rational)
inches =
    (Rational -> ArmRangeLower)
-> (ArmRangeLower -> Rational) -> Iso' Rational ArmRangeLower
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
      Rational -> ArmRangeLower
ArmRangeLower
      (\(ArmRangeLower Rational
x) -> Rational
x)

instance Thouinches ArmRangeLower where
  thouinches :: p ArmRangeLower (f ArmRangeLower) -> p Rational (f Rational)
thouinches =
    Rational -> Iso' Rational Rational
forall a. (Fractional a, Eq a) => a -> Iso' a a
multiplying Rational
1000 (p Rational (f Rational) -> p Rational (f Rational))
-> (p ArmRangeLower (f ArmRangeLower) -> p Rational (f Rational))
-> p ArmRangeLower (f ArmRangeLower)
-> p Rational (f Rational)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. p ArmRangeLower (f ArmRangeLower) -> p Rational (f Rational)
forall a. Inches a => Iso' Rational a
inches

instance Centimetres ArmRangeLower where
  centimetres :: p ArmRangeLower (f ArmRangeLower) -> p Rational (f Rational)
centimetres =
    Rational -> Iso' Rational Rational
forall a. (Fractional a, Eq a) => a -> Iso' a a
dividing (Integer
254 Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
100) (p Rational (f Rational) -> p Rational (f Rational))
-> (p ArmRangeLower (f ArmRangeLower) -> p Rational (f Rational))
-> p ArmRangeLower (f ArmRangeLower)
-> p Rational (f Rational)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. p ArmRangeLower (f ArmRangeLower) -> p Rational (f Rational)
forall a. Inches a => Iso' Rational a
inches

instance Semigroup ArmRangeLower where
  <> :: ArmRangeLower -> ArmRangeLower -> ArmRangeLower
(<>) =
    ArmRangeLower -> ArmRangeLower -> ArmRangeLower
forall a. Monoid a => a -> a -> a
mappend

instance Monoid ArmRangeLower where
  mempty :: ArmRangeLower
mempty =
    Rational -> ArmRangeLower
ArmRangeLower Rational
0
  ArmRangeLower Rational
w1 mappend :: ArmRangeLower -> ArmRangeLower -> ArmRangeLower
`mappend` ArmRangeLower Rational
w2 =
    Rational -> ArmRangeLower
ArmRangeLower (Rational
w1 Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
+ Rational
w2)