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

module Data.Aviation.WB.Arm.ArmStatic(
  ArmStatic
, HasArmStatic(..)
, HasArmStatics(..)
, SetArmStatic(..)
, HasArmStatic0(..)
) 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 ArmStatic =
  ArmStatic
    Rational
  deriving (ArmStatic -> ArmStatic -> Bool
(ArmStatic -> ArmStatic -> Bool)
-> (ArmStatic -> ArmStatic -> Bool) -> Eq ArmStatic
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArmStatic -> ArmStatic -> Bool
$c/= :: ArmStatic -> ArmStatic -> Bool
== :: ArmStatic -> ArmStatic -> Bool
$c== :: ArmStatic -> ArmStatic -> Bool
Eq, Eq ArmStatic
Eq ArmStatic
-> (ArmStatic -> ArmStatic -> Ordering)
-> (ArmStatic -> ArmStatic -> Bool)
-> (ArmStatic -> ArmStatic -> Bool)
-> (ArmStatic -> ArmStatic -> Bool)
-> (ArmStatic -> ArmStatic -> Bool)
-> (ArmStatic -> ArmStatic -> ArmStatic)
-> (ArmStatic -> ArmStatic -> ArmStatic)
-> Ord ArmStatic
ArmStatic -> ArmStatic -> Bool
ArmStatic -> ArmStatic -> Ordering
ArmStatic -> ArmStatic -> ArmStatic
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 :: ArmStatic -> ArmStatic -> ArmStatic
$cmin :: ArmStatic -> ArmStatic -> ArmStatic
max :: ArmStatic -> ArmStatic -> ArmStatic
$cmax :: ArmStatic -> ArmStatic -> ArmStatic
>= :: ArmStatic -> ArmStatic -> Bool
$c>= :: ArmStatic -> ArmStatic -> Bool
> :: ArmStatic -> ArmStatic -> Bool
$c> :: ArmStatic -> ArmStatic -> Bool
<= :: ArmStatic -> ArmStatic -> Bool
$c<= :: ArmStatic -> ArmStatic -> Bool
< :: ArmStatic -> ArmStatic -> Bool
$c< :: ArmStatic -> ArmStatic -> Bool
compare :: ArmStatic -> ArmStatic -> Ordering
$ccompare :: ArmStatic -> ArmStatic -> Ordering
$cp1Ord :: Eq ArmStatic
Ord, Int -> ArmStatic -> ShowS
[ArmStatic] -> ShowS
ArmStatic -> String
(Int -> ArmStatic -> ShowS)
-> (ArmStatic -> String)
-> ([ArmStatic] -> ShowS)
-> Show ArmStatic
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ArmStatic] -> ShowS
$cshowList :: [ArmStatic] -> ShowS
show :: ArmStatic -> String
$cshow :: ArmStatic -> String
showsPrec :: Int -> ArmStatic -> ShowS
$cshowsPrec :: Int -> ArmStatic -> ShowS
Show)

makeClassy ''ArmStatic

class HasArmStatics a where
  armStatics ::
    Traversal'
      a
      ArmStatic

instance HasArmStatics ArmStatic where
  armStatics :: (ArmStatic -> f ArmStatic) -> ArmStatic -> f ArmStatic
armStatics =
    (ArmStatic -> f ArmStatic) -> ArmStatic -> f ArmStatic
forall c. HasArmStatic c => Lens' c ArmStatic
armStatic

class SetArmStatic a where
  setArmStatic ::
    Setter'
      a
      ArmStatic

instance SetArmStatic ArmStatic where
  setArmStatic :: (ArmStatic -> f ArmStatic) -> ArmStatic -> f ArmStatic
setArmStatic =
    (ArmStatic -> f ArmStatic) -> ArmStatic -> f ArmStatic
forall c. HasArmStatic c => Lens' c ArmStatic
armStatic

class HasArmStatic0 a where
  armStatic0 ::
    Lens'
      a
      (Maybe ArmStatic)

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

instance Thouinches ArmStatic where
  thouinches :: p ArmStatic (f ArmStatic) -> 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 ArmStatic (f ArmStatic) -> p Rational (f Rational))
-> p ArmStatic (f ArmStatic)
-> 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 ArmStatic (f ArmStatic) -> p Rational (f Rational)
forall a. Inches a => Iso' Rational a
inches

instance Centimetres ArmStatic where
  centimetres :: p ArmStatic (f ArmStatic) -> 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 ArmStatic (f ArmStatic) -> p Rational (f Rational))
-> p ArmStatic (f ArmStatic)
-> 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 ArmStatic (f ArmStatic) -> p Rational (f Rational)
forall a. Inches a => Iso' Rational a
inches

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

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