-- SPDX-FileCopyrightText: 2022-24 Gregor Kleen <gregor.kleen@ifi.lmu.de>,Steffen Jost <s.jost@fraport.de>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later

-- Table recording all significant changes of database-state for auditing purposes
TransactionLog
  time UTCTime
  instance InstanceId
  initiator UserId Maybe -- User associated with performing this action
  remote IP Maybe -- Remote party that triggered this action via HTTP
  info Value -- JSON-encoded `Transaction`. Value allows full backwards compatibility
  deriving Eq Read Show Generic

InterfaceLog  
  interface Text
  subtype   Text
  write     Bool                  -- requestMethod /= GET, i.e. True implies a write to FRADrive
  time      UTCTime
  rows      Int Maybe             -- number of datasets transmitted  
  info      Text                  -- addtional status information
  success   Bool default=true     -- false logs a failure; but it will be overwritten by next transaction, but logged in TransactionLog
  UniqueInterfaceSubtypeWrite interface subtype write
  deriving Eq Read Show Generic

InterfaceHealth
  interface Text
  subtype   Text Maybe
  write     Bool Maybe
  hours     Int                   -- negative number: never expires, i.e. if the last entry is a success, this remains indefinitely
  UniqueInterfaceHealth interface subtype write !force -- Note that nullable fields must be either empty or unique
  deriving Eq Read Show Generic

ProblemLog  
  time        UTCTime default=now()
  info        Value                 -- generic JSON Value allows maximum backwards compatibility
  solved      UTCTime Maybe
  solver      UserId Maybe          -- User who marked this problem as done
  deriving Eq Read Show Generic