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

Sheet   -- exercise sheet for a given course
    course          CourseId OnDeleteCascade OnUpdateCascade
    name            (CI Text)
    description     StoredMarkup Maybe
    type            (SheetType SqlBackendKey) -- ExamPartId; Does it count towards overall course grade?
    grouping        SheetGroup       -- May participants submit in groups of certain sizes?
    markingText     StoredMarkup Maybe -- Instructons for correctors, included in marking templates
    visibleFrom     UTCTime Maybe    -- Invisible to enrolled participants before
    activeFrom      UTCTime Maybe    -- Download of questions and submission is permitted afterwards
    activeTo        UTCTime Maybe    -- Submission is only permitted before
    hintFrom        UTCTime Maybe    -- Additional files are made available
    solutionFrom    UTCTime Maybe    -- Solution is made available
    submissionMode  SubmissionMode   -- Submission upload by students and/or through tutors?
    autoDistribute  Bool default=false  -- Should correctors be assigned submissions automagically?
    anonymousCorrection Bool default=true
    requireExamRegistration ExamId Maybe -- Students may only submit if they are registered for the given exam
    allowNonPersonalisedSubmission Bool default=true
    authorshipStatementMode SheetAuthorshipStatementMode default='exam'
    authorshipStatementExam ExamId Maybe
    authorshipStatement AuthorshipStatementDefinitionId Maybe  -- sheet-specific authorship statement; for exam-unrelated sheets and as exam setting overrides
    CourseSheet course name
    deriving Generic
SheetEdit                     -- who edited when a row in table "Course", kept indefinitely
    user            UserId
    time            UTCTime
    sheet           SheetId OnDeleteCascade OnUpdateCascade
    deriving Generic

-- For anonoymous external submissions (i.e. paper submission tracked in uni2work)
-- Map pseudonyms to users injectively in the context of a single sheet; for the next sheet all-new pseudonyms need to be created
-- Chosen uniformly at random when the submitting user presses a button on the view of a sheet
SheetPseudonym
    sheet           SheetId OnDeleteCascade OnUpdateCascade
    pseudonym       Pseudonym -- 24-bit number that should be attached to external submission (i.e. written on the submitted paper); encoded as two english words akin to PGP-Wordlist
    user            UserId
    UniqueSheetPseudonym sheet pseudonym
    UniqueSheetPseudonymUser sheet user
    deriving Generic
SheetCorrector                -- grant corrector role to user for a sheet
    user            UserId
    sheet           SheetId OnDeleteCascade OnUpdateCascade
    load            Load      -- portion of work that will be assigned to this corrector
    state           CorrectorState default='CorrectorNormal' -- whether a corrector is assigned his load this time (e.g. in case of sickness)
    UniqueSheetCorrector user sheet
    deriving Show Eq Ord Generic
SheetFile                     -- a file that is part of an exercise sheet
    sheet    SheetId OnDeleteCascade OnUpdateCascade
    type     SheetFileType   -- excercise, marking, hint or solution
    title    FilePath
    content  FileContentReference Maybe
    modified UTCTime
    UniqueSheetFile sheet type title
    deriving Generic
PersonalisedSheetFile
    sheet    SheetId OnDeleteCascade OnUpdateCascade
    user     UserId
    type     SheetFileType
    title    FilePath
    content  FileContentReference Maybe
    modified UTCTime
    UniquePersonalisedSheetFile sheet user type title
    deriving Eq Ord Read Show Generic

FallbackPersonalisedSheetFilesKey
    course     CourseId OnDeleteCascade OnUpdateCascade
    index      Word24
    secret     ByteString
    generated  UTCTime
    UniqueFallbackPersonalisedSheetFilesKey course index
    deriving Generic
