-- | prints an RTable with an RTuple format specification
printfRTable :: RTupleFormat -> RTable -> IO()
printfRTable rtupFmt rtab = -- undefined
    if isRTabEmpty rtab
        then
            do 
                putStrLn "-------------------------------------------"
                putStrLn " 0 rows returned"
                putStrLn "-------------------------------------------"

        else
            do
                -- find the max value-length for each column, this will be the width of the box for this column
                let listOfLengths = getMaxLengthPerColumnFmt rtupFmt rtab

                --debug
                --putStrLn $ "List of Lengths: " ++ show listOfLengths

                printContLineFmt rtupFmt listOfLengths '-' rtab
                -- print the Header
                printRTableHeaderFmt rtupFmt listOfLengths rtab 

                -- print the body
                printRTabBodyFmt rtupFmt listOfLengths $ V.toList rtab

                -- print number of rows returned
                let numrows = V.length rtab
                if numrows == 1
                    then 
                        putStrLn $ "\n"++ (show $ numrows) ++ " row returned"        
                    else
                        putStrLn $ "\n"++ (show $ numrows) ++ " rows returned"        

                printContLineFmt rtupFmt listOfLengths '-' rtab
                where
                    -- [Int] a List of width per column to be used in the box definition        
                    printRTabBodyFmt :: RTupleFormat -> [Int] -> [RTuple] -> IO()
                    printRTabBodyFmt _ _ [] = putStrLn ""            
                    printRTabBodyFmt rtupf ws (rtup : rest) = do
                            printRTupleFmt rtupf ws rtup
                            printRTabBodyFmt rtupf ws rest


-- | printRTable : Print the input RTable on screen
printfRTable :: RTupleFormat -> RTable -> IO()
printfRTable rtupFmt rtab = -- undefined
    if isRTabEmpty rtab
        then
            do 
                putStrLn "-------------------------------------------"
                putStrLn " 0 rows returned"
                putStrLn "-------------------------------------------"

        else
            do
                -- find the max value-length for each column, this will be the width of the box for this column
                let listOfLengths = getMaxLengthPerColumnFmt rtupFmt rtab

                --debug
                --putStrLn $ "List of Lengths: " ++ show listOfLengths

                printContLineFmt rtupFmt listOfLengths '-' rtab
                -- print the Header
                printRTableHeaderFmt rtupFmt listOfLengths rtab 

                -- print the body
                printRTabBodyFmt rtupFmt listOfLengths $ V.toList rtab

                -- print number of rows returned
                let numrows = V.length rtab
                if numrows == 1
                    then 
                        putStrLn $ "\n"++ (show $ numrows) ++ " row returned"        
                    else
                        putStrLn $ "\n"++ (show $ numrows) ++ " rows returned"        

                printContLineFmt rtupFmt listOfLengths '-' rtab
                where
                    -- [Int] a List of width per column to be used in the box definition        
                    printRTabBodyFmt :: RTupleFormat -> [Int] -> [RTuple] -> IO()
                    printRTabBodyFmt _ _ [] = putStrLn ""            
                    printRTabBodyFmt rtupf ws (rtup : rest) = do
                            printRTupleFmt rtupf ws rtup
                            printRTabBodyFmt rtupf ws rest


-- | printRTable : Print the input RTable on screen
printfRTable rtupFmt rtab = -- undefined
    if isRTabEmpty rtab
        then
            do 
                putStrLn "-------------------------------------------"
                putStrLn " 0 rows returned"
                putStrLn "-------------------------------------------"

        else
            do
                -- find the max value-length for each column, this will be the width of the box for this column
                let listOfLengths = getMaxLengthPerColumnFmt rtupFmt rtab

                --debug
                --putStrLn $ "List of Lengths: " ++ show listOfLengths

                printContLineFmt rtupFmt listOfLengths '-' rtab
                -- print the Header
                printRTableHeaderFmt rtupFmt listOfLengths rtab 

                -- print the body
                printRTabBodyFmt rtupFmt listOfLengths $ V.toList rtab

                -- print number of rows returned
                let numrows = V.length rtab
                if numrows == 1
                    then 
                        putStrLn $ "\n"++ (show $ numrows) ++ " row returned"        
                    else
                        putStrLn $ "\n"++ (show $ numrows) ++ " rows returned"        

                printContLineFmt rtupFmt listOfLengths '-' rtab
                where
                    -- [Int] a List of width per column to be used in the box definition        
                    printRTabBodyFmt :: RTupleFormat -> [Int] -> [RTuple] -> IO()
                    printRTabBodyFmt _ _ [] = putStrLn ""            
                    printRTabBodyFmt rtupf ws (rtup : rest) = do
                            printRTupleFmt rtupf ws rtup
                            printRTabBodyFmt rtupf ws rest


-- | printRTable : Print the input RTable on screen