{- Wally World Marketplace POP Project, Code Template
   H. Conrad Cunningham
   
1234567890123456789012345678901234567890123456789012345678901234567890

2018-10-19: Created from instructor solution

-}

module WWMPOP
-- ( formatDollars, formatLine, formatLines, calcSubtotal,
--   formatAmt, formatBill, look, priceCart, makeBill, makeReceipt,
--   removePL, addPL
-- )
where

type BarCode    = Int
type Price      = Int
type Name       = String
type PriceList  = [(BarCode,Name,Price)]
type CartItems  = [BarCode]
type CartPrices = [(Name,Price)]
type Bill       = (CartPrices, Price, Price, Price)

-- Sales tax rate as a fraction
taxRate :: Double
taxRate = 0.07

-- Line width (not including newline)
lineWidth :: Int
lineWidth = 34

{- BEGIN EXAMPLE RECEIPT
     Wally World Marketplace

Vanilla yogurt cups (4).......1.88
Ground turkey (1 lb)..........3.16
Toasted oat cereal............2.99
Ground turkey (1 lb)..........3.16
Black tea bags (100)..........3.07
Athletic socks (6)............8.25
Claw hammer...................7.88
32-in. television...........139.49
Zero sugar cola (12)..........3.34

Subtotal....................176.26
Tax..........................12.34
Total.......................188.60
-}

-- Exercise #1
-- formatDollars :: Price -> String

-- Exercise #2
-- formatLine :: (Name, Price) -> String 

-- Exercise #3
-- formatLines :: CartPrices -> String

-- Exercise #3
-- calcSubtotal :: CartPrices -> Price

-- Exercise #5
-- formatAmt :: String -> Price -> String

-- Exercise #6
-- formatBill :: Bill -> String

-- Exercise #7
-- look :: PriceList -> BarCode -> (Name,Price)

-- (Name,Price) tuple for Barcode not in PriceList
unknown :: (Name,Price)
-- unknown = ("Unknown Item", 0)
unknown = ("None", 0)

-- Exercise #8
-- priceCart :: PriceList -> CartItems -> CartPrices

-- Exercise #9
-- makeBill :: CartPrices -> Bill 

-- Exercise #10
-- makeReceipt :: PriceList -> CartItems -> String 

-- Exercise #11
-- removePL :: PriceList -> BarCode -> PriceList
-- addPL :: PriceList -> BarCode -> (Name,Price) -> PriceList

-- Examples from description

testinput = [ 1848, 1620, 1492, 1620, 1773, 2525, 9595, 1945, 1066 ]

database :: PriceList
database = [ (1848, "Vanilla yogurt cups (4)",    188),
             (1620, "Ground turkey (1 lb)",       316), 
             (1492, "Corn flakes cereal",         299), 
             (1773, "Black tea bags (100)",       307), 
             (2525, "Athletic socks (6)",         825), 
             (9595, "Claw hammer",                788), 
             (1945, "32-in TV",                 13949), 
             (1066, "Zero sugar cola (12)",       334),
             (2018, "Haskell programming book",  4495)
           ]

-- Other testing definitions

testreceipt1 = makeReceipt database testinput

database2 = addPL database 2018 ("ELIFP",100)

testreceipt2 = makeReceipt database2 (testinput ++ [2018])

main = do
    putStr testreceipt1
    putStr (show database2)
    putStr testreceipt2
