aboutsummaryrefslogtreecommitdiff
path: root/lib/Malodivo/Types/Bill.hs
blob: 336c0fb76517f8d626aff169fe36e057600ecf4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{-|

A bill is a proposed law put before the Parliament to consider and
possibly implement.  Bills can be encoded to and decoded from JSON.

>>> :set -XOverloadedStrings
>>> import Data.Aeson (decode, encode)
>>> import Data.Maybe (fromJust)
>>> import Malodivo.Types.Ministry (Ministry(..))

>>> let billGreateWall = Bill { name = "The Great Wall of Malodivo", ministry = Defense, amount = 4000 }
>>> encode billGreateWall
"{\"amount\":4000,\"name\":\"The Great Wall of Malodivo\",\"ministry\":\"Defense\"}"

>>> let billShelters = fromJust $ decode "{\"amount\":1234,\"name\":\"Shelters for the Homeless\",\"ministry\":\"Welfare\"}"
>>> billShelters :: Bill
Bill {name = "Shelters for the Homeless", ministry = Welfare, amount = 1234}

>>> ministry <$> [billShelters, billGreateWall]
[Welfare,Defense]

>>> sum $ amount <$> [billShelters, billGreateWall]
5234

-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}

module Malodivo.Types.Bill
  ( Bill(..)
  ) where

import GHC.Generics (Generic)

import Data.Aeson (FromJSON, ToJSON)
import Data.Text (Text)

import Malodivo.Types.Ministry (Ministry)

data Bill = Bill
  { name :: Text -- ^ the name of a bill, e. g. \"An Act to Construct the Great Wall of Malodivo\".
  , ministry :: Ministry -- ^ the ministry getting funds to implement a bill.
  , amount :: Integer -- ^ the amount of funds required to implement a bill.
  } deriving (Show, Generic, FromJSON, ToJSON)