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

-- Messages shown to all users as soon as they visit the site/log in (i.e.: "System is going down for maintenance next sunday")
-- Only administrators (of any school) should be able to create these via a web-interface
SystemMessage json
    from                UTCTime Maybe -- Message is not shown before this date has passed (never shown, if null)
    to                  UTCTime Maybe -- Message is shown until this date has passed (shown forever, if null)
    onVolatileClusterSettings SystemMessageVolatileClusterSettings default="'[]'::jsonb" -- Message is shown when given volatile cluster settings have given values
    newsOnly            Bool default=false
    authenticatedOnly   Bool -- Show message to all users upon visiting the site or only upon login?
    severity            MessageStatus -- Success, Warning, Error, Info, ...
    manualPriority      Word64  Maybe
    created             UTCTime default=now()
    lastChanged         UTCTime default=now()
    lastUnhide          UTCTime default=now()
    defaultLanguage     Lang -- Language of @content@ and @summary@
    content             StoredMarkup -- Detailed message shown when clicking on the @summary@-popup or when no @summary@ is specified
    summary             StoredMarkup Maybe
    deriving Generic

SystemMessageTranslation -- Translation of a @SystemMessage@ into another language; which language to choose is determined by user-sent HTTP-headers
    message             SystemMessageId OnDeleteCascade OnUpdateCascade
    language            Lang
    content             StoredMarkup
    summary             StoredMarkup Maybe
    UniqueSystemMessageTranslation message language
    deriving Generic

SystemMessageHidden
    message             SystemMessageId OnDeleteCascade OnUpdateCascade
    user                UserId
    time                UTCTime
    UniqueSystemMessageHidden user message
    deriving Generic