module Ledger.Commodity
( Commodity
, CommodityInfo(..), HasCommodityInfo(..)
, defaultCommodityInfo
, CommodityMap(..), HasCommodityMap(..)
, extendByDigits
) where
import Control.Lens
import Data.IntMap (IntMap, Key)
import qualified Data.IntMap as IntMap
import Data.Map (Map)
import Data.Ratio
import Data.Semigroup
import Data.Text (Text)
import Data.Thyme.Time
import Prelude hiding (lookup)
type Commodity = Key
extendByDigits :: Int
extendByDigits = 6
data CommodityInfo = CommodityInfo
{ _commSymbol :: !Text
, _commPrecision :: !Int
, _commSuffixed :: !Bool
, _commSeparated :: !Bool
, _commThousands :: !Bool
, _commDecimalComma :: !Bool
, _commNoMarket :: !Bool
, _commBuiltin :: !Bool
, _commKnown :: !Bool
, _commPrimary :: !Bool
, _commHistory :: !(IntMap (Map UTCTime Rational))
} deriving (Eq, Read, Show)
makeClassy ''CommodityInfo
defaultCommodityInfo :: CommodityInfo
defaultCommodityInfo = CommodityInfo
{ _commSymbol = ""
, _commPrecision = 0
, _commSuffixed = False
, _commSeparated = False
, _commThousands = True
, _commDecimalComma = False
, _commNoMarket = False
, _commBuiltin = False
, _commKnown = False
, _commPrimary = False
, _commHistory = IntMap.empty
}
data CommodityMap = CommodityMap
{ _commodities :: !(IntMap CommodityInfo)
}
deriving (Eq, Read, Show)
makeClassy ''CommodityMap
instance Semigroup CommodityMap where
CommodityMap x <> CommodityMap y = CommodityMap (x <> y)
instance Monoid CommodityMap where
mempty = CommodityMap mempty
x `mappend` y = x <> y