{-
This is the main module for Student Portal

You should edit this file in two ways:
 1) Insert your database connection string in the proper place.
 2) Implement the three functions pgGetInformation, pgRegisterStudent
    and pgUnregisterStudent.
-}

-- Types
import StudentPortalCommon
import SqlRows -- functions for convenient data conversion

-- User interface (choose one)
import StudentPortalCLI -- use the command-line interface, or
--import StudentPortal3p -- use the ThreepennyGUI interface


-- Database connectivity library, see
-- <http://hackage.haskell.org/package/HDBC>
-- <http://hackage.haskell.org/package/HDBC-postgresql>
import Database.HDBC(fromSql,toSql,quickQuery',run,withTransaction,
                     handleSqlError)
import Database.HDBC.PostgreSQL(Connection,connectPostgreSQL)

-- Insert your database connection string below.
-- The format of the connection string is documented at
-- <https://www.postgresql.org/docs/8.1/libpq.html#LIBPQ-CONNECT>
database = "dbname=university"

--------------------------------------------------------------------------------

main = do conn <- connectPostgreSQL database
          let dbi = SP { getInformation = pgGetInformation conn,
                         registerStudent = pgRegisterStudent conn,
                         unregisterStudent = pgUnregisterStudent conn }
          studentPortal dbi


--------------------------------------------------------------------------------
-- * Database access functions

{-| Given a student identification number, this function returns
 * the name of the student, the students national identification number
   and their issued login name (something similar to a CID)
 * the programme and branch (if any) that the student is following.
 * the courses that the student has read, along with the grade.
 * the courses that the student is registered to.
       (queue position if the student is waiting for the course)
 * the number of mandatory courses that the student has yet to read.
 * whether or not the student fulfills the requirements for graduation
-}
pgGetInformation :: Connection -> Idnr -> IO StudentInformation
pgGetInformation conn idnr =
  error "pgGetInformation NOT IMPLEMENTED YET"

-- | Given a student id number and a course code, this function
-- tries to register the student to that course.
pgRegisterStudent :: Connection -> Idnr -> CourseCode -> IO StatusMessage
pgRegisterStudent conn idnr course =
  error "pgResisterStudent NOT IMPLEMENTED YET"

-- | Given a student id number and a course code, this function
-- unregisters the student from that course.
pgUnregisterStudent :: Connection -> Idnr -> CourseCode -> IO StatusMessage
  error "pgUnresisterStudent NOT IMPLEMENTED YET"