-- SPDX-FileCopyrightText: 2022 Steffen Jost <jost@tcs.ifi.lmu.de>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later



module Handler.Utils.Qualification 
  ( module Handler.Utils.Qualification
  ) where 

import Import


upsertQualificationUser :: QualificationId -> Day -> Day -> UserId -> DB ()
upsertQualificationUser  qualificationUserQualification today qualificationUserValidUntil qualificationUserUser = do   
  Entity quid _ <- upsert
    QualificationUser
      { qualificationUserLastRefresh =  today
      , qualificationUserFirstHeld   =  today
      , qualificationUserBlockedDue  =  Nothing
      , ..
      }
    [ QualificationUserValidUntil    =. qualificationUserValidUntil
    , QualificationUserLastRefresh   =. today
    , QualificationUserBlockedDue    =. Nothing
    ]
  audit TransactionQualificationUserEdit
    { transactionQualificationUser        = quid
    , transactionQualification            = qualificationUserQualification
    , transactionUser                     = qualificationUserUser
    , transactionQualificationValidUntil  = qualificationUserValidUntil
    }