aboutsummaryrefslogtreecommitdiff
path: root/cmd/Main/Output.hs
blob: 107e8fd772c67bd836b2ca4a3a5a0eb22b8f419d (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
{-
This modules describes output data for the command line utlity.
-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}

module Main.Output
  ( Output
  , encode
  ) where

import GHC.Generics (Generic)

import Data.Aeson (ToJSON)

import Malodivo.Types.Bill (Bill)
import Malodivo.Types.District (DistrictFunds, DistrictInfo, df2di)

type Output = [BillBudget]

-- | JSON-friendly type. It describes contribution of each district into a bill.
data BillBudget = BillBudget
  { bill :: Bill
  , districts :: [DistrictInfo]
  } deriving (Generic, ToJSON)

-- | Translate into JSON-friendly format.
encode :: [(Bill, DistrictFunds)] -> Output
encode = map (\(b, df) -> BillBudget {bill = b, districts = df2di df})