-- SPDX-FileCopyrightText: 2022-2025 Sarah Vaupel <sarah.vaupel@uniworx.de>,-2024 Gregor Kleen <gregor.kleen@ifi.lmu.de>, Sarah Vaupel <sarah.vaupel@ifi.lmu.de>, Steffen Jost <jost@tcs.ifi.lmu.de>,Steffen Jost <s.jost@fraport.de>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later

module Model.Types.User where

import Import.NoModel
import Model.Types.TH.PathPiece


data SystemFunction
  = SystemExamOffice
  | SystemFaculty
  | SystemStudent
  | SystemPrinter
  deriving (Eq, Ord, Read, Show, Enum, Bounded, Generic)
  deriving anyclass (Universe, Finite, Hashable, NFData)

nullaryPathPiece ''SystemFunction $ camelToPathPiece' 1
pathPieceJSON ''SystemFunction
pathPieceJSONKey ''SystemFunction
derivePersistFieldPathPiece ''SystemFunction
pathPieceBinary ''SystemFunction



--------------------------------------------------------------------------------------
-- User related dataypes which are not stored in User itself, but in various places

data UserDrivingPermit = UserDrivingPermitB
                       | UserDrivingPermitB01
  deriving (Eq, Ord, Enum, Bounded, Generic, Universe, Finite, Hashable, NFData)

instance Show UserDrivingPermit where
  show UserDrivingPermitB   = "B"
  show UserDrivingPermitB01 = "B01" -- Brille notwendig

instance RenderMessage a UserDrivingPermit where
  renderMessage _foundation _languages = tshow

deriveJSON defaultOptions
  { constructorTagModifier = camelToPathPiece' 3
  } ''UserDrivingPermit
derivePersistFieldJSON ''UserDrivingPermit
nullaryPathPiece ''UserDrivingPermit $ camelToPathPiece' 3

data UserEyeExam = UserEyeExamSX
                 | UserEyeExamS01
  deriving (Eq, Ord, Enum, Bounded, Generic, Universe, Finite, Hashable, NFData)

instance Show UserEyeExam where
  show UserEyeExamSX  = "SX"
  show UserEyeExamS01 = "S01" -- Brille notwendig

instance RenderMessage a UserEyeExam where
  renderMessage _foundation _languages = tshow

deriveJSON defaultOptions
  { constructorTagModifier = camelToPathPiece' 3
  } ''UserEyeExam
derivePersistFieldJSON ''UserEyeExam
nullaryPathPiece ''UserEyeExam $ camelToPathPiece' 3

eyeExamFitsDrivingPermit :: UserEyeExam -> UserDrivingPermit -> Bool
eyeExamFitsDrivingPermit UserEyeExamSX  _                    = True
eyeExamFitsDrivingPermit UserEyeExamS01 UserDrivingPermitB01 = True
eyeExamFitsDrivingPermit _              _                    = False