module Company where

newtype DeptNo = DeptNo Int
   deriving (Eq, Ord, Show)

data Dept =
   Dept {
      deptnoDept :: DeptNo,
      dname :: String,
      loc :: String
   }
   deriving (Eq, Ord, Show)

dept :: [Dept]
dept =
   Dept (DeptNo 10) "ACCOUNTING" "NEW YORK" :
   Dept (DeptNo 20) "RESEARCH" "DALLAS" :
   Dept (DeptNo 30) "SALES" "CHICAGO" :
   Dept (DeptNo 40) "OPERATIONS" "BOSTON" :
   []



data Job =
   Clerk | Salesman | Manager | Analyst | President
   deriving (Eq, Ord, Enum, Show, Bounded)

newtype EmpNo = EmpNo Int
   deriving (Eq, Ord, Show)

data Emp =
   Emp {
      empno :: EmpNo,
      ename :: String,
      job :: Job,
      mgr :: Maybe EmpNo,
      sal :: Int,
      deptnoEmp :: DeptNo
   }
   deriving (Eq, Ord, Show)

emp :: [Emp]
emp =
   Emp (EmpNo 7369) "SMITH" Clerk (Just (EmpNo 7902)) 800 (DeptNo 20) :
   Emp (EmpNo 7499) "ALLEN" Salesman (Just (EmpNo 7698)) 1600 (DeptNo 30) :
   Emp (EmpNo 7521) "WARD" Salesman (Just (EmpNo 7698)) 1250 (DeptNo 30) :
   Emp (EmpNo 7566) "JONES" Manager (Just (EmpNo 7839)) 2975 (DeptNo 20) :
   Emp (EmpNo 7654) "MARTIN" Salesman (Just (EmpNo 7698)) 1250 (DeptNo 30) :
   Emp (EmpNo 7698) "BLAKE" Manager (Just (EmpNo 7839)) 2850 (DeptNo 30) :
   Emp (EmpNo 7782) "CLARK" Manager (Just (EmpNo 7839)) 2450 (DeptNo 10) :
   Emp (EmpNo 7788) "SCOTT" Analyst (Just (EmpNo 7566)) 3000 (DeptNo 20) :
   Emp (EmpNo 7839) "KING" President Nothing 5000 (DeptNo 10) :
   Emp (EmpNo 7844) "TURNER" Salesman (Just (EmpNo 7698)) 1500 (DeptNo 30) :
   Emp (EmpNo 7876) "ADAMS" Clerk (Just (EmpNo 7788)) 1100 (DeptNo 20) :
   Emp (EmpNo 7900) "JAMES" Clerk (Just (EmpNo 7698)) 950 (DeptNo 30) :
   Emp (EmpNo 7902) "FORD" Analyst (Just (EmpNo 7566)) 3000 (DeptNo 20) :
   Emp (EmpNo 7934) "MILLER" Clerk (Just (EmpNo 7782)) 1300 (DeptNo 10) :
   []


class    DeptNoField r    where deptno :: r -> DeptNo
instance DeptNoField Dept where deptno = deptnoDept
instance DeptNoField Emp  where deptno = deptnoEmp
