{-# LANGUAGE DataKinds     #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia   #-}

module Haspara.Accounting.Account where

import Data.Hashable                  (Hashable)
import Deriving.Aeson                 (CustomJSON(CustomJSON), FromJSON, Generic, ToJSON)
import Deriving.Aeson.Stock           (PrefixedSnake)
import Haspara.Accounting.AccountKind (AccountKind)


-- | Account model.
--
-- >>> import Haspara.Accounting.AccountKind (AccountKind(..))
-- >>> import qualified Data.Aeson as Aeson
-- >>> let acc = Account AccountKindAsset (1 ::Int)
-- >>> Aeson.encode acc
-- "{\"kind\":\"ASSET\",\"object\":1}"
-- >>> Aeson.decode (Aeson.encode acc) :: Maybe (Account Int)
-- Just (Account {accountKind = AccountKindAsset, accountObject = 1})
-- >>> Aeson.decode (Aeson.encode acc) == Just acc
-- True
data Account o = Account
  { Account o -> AccountKind
accountKind   :: !AccountKind
  , Account o -> o
accountObject :: !o
  } deriving (Account o -> Account o -> Bool
(Account o -> Account o -> Bool)
-> (Account o -> Account o -> Bool) -> Eq (Account o)
forall o. Eq o => Account o -> Account o -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Account o -> Account o -> Bool
$c/= :: forall o. Eq o => Account o -> Account o -> Bool
== :: Account o -> Account o -> Bool
$c== :: forall o. Eq o => Account o -> Account o -> Bool
Eq, (forall x. Account o -> Rep (Account o) x)
-> (forall x. Rep (Account o) x -> Account o)
-> Generic (Account o)
forall x. Rep (Account o) x -> Account o
forall x. Account o -> Rep (Account o) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall o x. Rep (Account o) x -> Account o
forall o x. Account o -> Rep (Account o) x
$cto :: forall o x. Rep (Account o) x -> Account o
$cfrom :: forall o x. Account o -> Rep (Account o) x
Generic, Eq (Account o)
Eq (Account o)
-> (Account o -> Account o -> Ordering)
-> (Account o -> Account o -> Bool)
-> (Account o -> Account o -> Bool)
-> (Account o -> Account o -> Bool)
-> (Account o -> Account o -> Bool)
-> (Account o -> Account o -> Account o)
-> (Account o -> Account o -> Account o)
-> Ord (Account o)
Account o -> Account o -> Bool
Account o -> Account o -> Ordering
Account o -> Account o -> Account o
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
forall o. Ord o => Eq (Account o)
forall o. Ord o => Account o -> Account o -> Bool
forall o. Ord o => Account o -> Account o -> Ordering
forall o. Ord o => Account o -> Account o -> Account o
min :: Account o -> Account o -> Account o
$cmin :: forall o. Ord o => Account o -> Account o -> Account o
max :: Account o -> Account o -> Account o
$cmax :: forall o. Ord o => Account o -> Account o -> Account o
>= :: Account o -> Account o -> Bool
$c>= :: forall o. Ord o => Account o -> Account o -> Bool
> :: Account o -> Account o -> Bool
$c> :: forall o. Ord o => Account o -> Account o -> Bool
<= :: Account o -> Account o -> Bool
$c<= :: forall o. Ord o => Account o -> Account o -> Bool
< :: Account o -> Account o -> Bool
$c< :: forall o. Ord o => Account o -> Account o -> Bool
compare :: Account o -> Account o -> Ordering
$ccompare :: forall o. Ord o => Account o -> Account o -> Ordering
$cp1Ord :: forall o. Ord o => Eq (Account o)
Ord, Int -> Account o -> ShowS
[Account o] -> ShowS
Account o -> String
(Int -> Account o -> ShowS)
-> (Account o -> String)
-> ([Account o] -> ShowS)
-> Show (Account o)
forall o. Show o => Int -> Account o -> ShowS
forall o. Show o => [Account o] -> ShowS
forall o. Show o => Account o -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Account o] -> ShowS
$cshowList :: forall o. Show o => [Account o] -> ShowS
show :: Account o -> String
$cshow :: forall o. Show o => Account o -> String
showsPrec :: Int -> Account o -> ShowS
$cshowsPrec :: forall o. Show o => Int -> Account o -> ShowS
Show)
  deriving (Value -> Parser [Account o]
Value -> Parser (Account o)
(Value -> Parser (Account o))
-> (Value -> Parser [Account o]) -> FromJSON (Account o)
forall o. FromJSON o => Value -> Parser [Account o]
forall o. FromJSON o => Value -> Parser (Account o)
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Account o]
$cparseJSONList :: forall o. FromJSON o => Value -> Parser [Account o]
parseJSON :: Value -> Parser (Account o)
$cparseJSON :: forall o. FromJSON o => Value -> Parser (Account o)
FromJSON, [Account o] -> Encoding
[Account o] -> Value
Account o -> Encoding
Account o -> Value
(Account o -> Value)
-> (Account o -> Encoding)
-> ([Account o] -> Value)
-> ([Account o] -> Encoding)
-> ToJSON (Account o)
forall o. ToJSON o => [Account o] -> Encoding
forall o. ToJSON o => [Account o] -> Value
forall o. ToJSON o => Account o -> Encoding
forall o. ToJSON o => Account o -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Account o] -> Encoding
$ctoEncodingList :: forall o. ToJSON o => [Account o] -> Encoding
toJSONList :: [Account o] -> Value
$ctoJSONList :: forall o. ToJSON o => [Account o] -> Value
toEncoding :: Account o -> Encoding
$ctoEncoding :: forall o. ToJSON o => Account o -> Encoding
toJSON :: Account o -> Value
$ctoJSON :: forall o. ToJSON o => Account o -> Value
ToJSON)
  via PrefixedSnake "account" (Account o)


instance Hashable o => Hashable (Account o)