{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE KindSignatures #-}
module PrettyPrint
( money
, rule
, fromBudget
) where
import Data.Pos (unP)
import Data.Proxy (Proxy (..))
import GHC.TypeLits
import Prettyprinter
import Budget (Budget)
import qualified Budget (needs, wants, savings)
import Money (PosMoney, unPosMoney)
fromBudget :: forall curr a b c. (KnownSymbol curr, KnownNat a, KnownNat b, KnownNat c) => Budget curr '(a, b, c) -> Doc ()
fromBudget budget = header <> hardline <> need <> hardline <> want <> hardline <> saving
where
header = "Budget with rule" <+> rule budget
need = fill width "Needs:" <+> money (Budget.needs budget)
want = fill width "Wants:" <+> money (Budget.wants budget)
saving = fill width "Savings:" <+> money (Budget.savings budget)
width = 8
rule :: forall a b c proxy (curr :: Symbol). (KnownNat a, KnownNat b, KnownNat c) => proxy curr '(a, b, c) -> Doc ()
rule _ = concatWith (surround "/") . map pretty $ [natVal (Proxy @a), natVal (Proxy @b), natVal (Proxy @c)]
money :: forall c. (KnownSymbol c) => PosMoney c -> Doc ()
money x = pretty currency <+> pretty value
where
value = unP . unPosMoney $ x
currency = symbolVal (Proxy @c)