printRTable ::
       RTable
    -> IO ()
printRTable rtab = 
    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 = getMaxLengthPerColumn rtab

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

                printContLine listOfLengths '-' rtab
                -- print the Header
                printRTableHeader listOfLengths rtab 

                -- print the body
                printRTabBody 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"        

                printContLine listOfLengths '-' rtab
                where
                    -- [Int] a List of width per column to be used in the box definition        
                    printRTabBody :: [Int] -> [RTuple] -> IO()
                    printRTabBody _ [] = putStrLn ""            
                    printRTabBody ws (rtup : rest) = do
                            printRTuple ws rtup
                            printRTabBody ws rest

-- | Returns the max length of the String representation of each value, for each column of the input RTable. 
-- It returns the lengths in the column order specified by the input RTupleFormat parameter
printRTable ::
       RTable
    -> IO ()
printRTable rtab = 
    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 = getMaxLengthPerColumn rtab

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

                printContLine listOfLengths '-' rtab
                -- print the Header
                printRTableHeader listOfLengths rtab 

                -- print the body
                printRTabBody 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"        

                printContLine listOfLengths '-' rtab
                where
                    -- [Int] a List of width per column to be used in the box definition        
                    printRTabBody :: [Int] -> [RTuple] -> IO()
                    printRTabBody _ [] = putStrLn ""            
                    printRTabBody ws (rtup : rest) = do
                            printRTuple ws rtup
                            printRTabBody ws rest

-- | Returns the max length of the String representation of each value, for each column of the input RTable. 
-- It returns the lengths in the column order specified by the input RTupleFormat parameter
printRTable rtab = 
    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 = getMaxLengthPerColumn rtab

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

                printContLine listOfLengths '-' rtab
                -- print the Header
                printRTableHeader listOfLengths rtab 

                -- print the body
                printRTabBody 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"        

                printContLine listOfLengths '-' rtab
                where
                    -- [Int] a List of width per column to be used in the box definition        
                    printRTabBody :: [Int] -> [RTuple] -> IO()
                    printRTabBody _ [] = putStrLn ""            
                    printRTabBody ws (rtup : rest) = do
                            printRTuple ws rtup
                            printRTabBody ws rest

-- | Returns the max length of the String representation of each value, for each column of the input RTable. 
-- It returns the lengths in the column order specified by the input RTupleFormat parameter