{-|
Module      : Gargantext.Database.Init
Description : Triggers configuration
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

Ngrams by node enable contextual metrics.

-}

{-# LANGUAGE QuasiQuotes       #-}

module Gargantext.Database.Admin.Trigger.Init
  where

import Data.Text (Text)
import Gargantext.Database.Admin.Trigger.NodeNodeNgrams (triggerCountInsert, triggerCountInsert2)
import Gargantext.Database.Admin.Trigger.Nodes (triggerSearchUpdate, triggerUpdateHash)
import Gargantext.Database.Admin.Trigger.NodesNodes (triggerDeleteCount, triggerInsertCount, triggerUpdateAdd, triggerUpdateDel, MasterListId) -- , triggerCoocInsert)
import Gargantext.Database.Prelude (Cmd)
import Gargantext.Prelude

------------------------------------------------------------------------
initFirstTriggers :: Text -> Cmd err [Int64]
initFirstTriggers :: Text -> Cmd err [Int64]
initFirstTriggers Text
secret = do
  Int64
t0  <- Text -> Cmd err Int64
forall err. HasDBid NodeType => Text -> Cmd err Int64
triggerUpdateHash Text
secret
  [Int64] -> m [Int64]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Int64
t0]

initLastTriggers :: MasterListId -> Cmd err [Int64]
initLastTriggers :: MasterListId -> Cmd err [Int64]
initLastTriggers MasterListId
lId = do
  Int64
t0  <- m Int64
forall err. HasDBid NodeType => Cmd err Int64
triggerSearchUpdate
  Int64
t1 <- m Int64
forall err. HasDBid NodeType => Cmd err Int64
triggerCountInsert
  Int64
t1' <- m Int64
forall err. HasDBid NodeType => Cmd err Int64
triggerCountInsert2
  -- t1'' <- triggerCoocInsert lId
  Int64
t2 <- MasterListId -> Cmd err Int64
forall err. MasterListId -> Cmd err Int64
triggerDeleteCount MasterListId
lId
  Int64
t3 <- MasterListId -> Cmd err Int64
forall err. MasterListId -> Cmd err Int64
triggerInsertCount MasterListId
lId
  Int64
t4 <- MasterListId -> Cmd err Int64
forall err. MasterListId -> Cmd err Int64
triggerUpdateAdd   MasterListId
lId
  Int64
t5 <- MasterListId -> Cmd err Int64
forall err. MasterListId -> Cmd err Int64
triggerUpdateDel   MasterListId
lId
  [Int64] -> m [Int64]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Int64
t0
       ,Int64
t1
       ,Int64
t1'
       -- ,t1''
       ,Int64
t2
       ,Int64
t3
       ,Int64
t4
       ,Int64
t5]