module UnliftIO.AutoUpdate.Types where

import Data.Functor.Identity

{- | Settings to control how values are updated.

 This should be constructed using 'defaultUpdateSettings' and record
 update syntax, e.g.:

 @
 let settings = 'defaultUpdateSettings' { 'updateAction' = 'Data.Time.Clock.getCurrentTime' }
 @

 @since 0.1.0
-}
data UpdateSettings m a = UpdateSettings
  { forall (m :: * -> *) a. UpdateSettings m a -> Int
updateFreq :: Int
  -- ^ Microseconds between update calls. Same considerations as
  -- 'Control.Concurrent.threadDelay' apply.
  --
  -- Default: 1000000 microseconds (1 second)
  --
  -- @since 0.1.0
  , forall (m :: * -> *) a. UpdateSettings m a -> Int
updateSpawnThreshold :: Int
  -- ^ Obsoleted field.
  --
  -- @since 0.1.0
  , forall (m :: * -> *) a. UpdateSettings m a -> m a
updateAction :: m a
  -- ^ Action to be performed to get the current value.
  --
  -- Default: does nothing.
  --
  -- @since 0.1.0
  , forall (m :: * -> *) a. UpdateSettings m a -> String
updateThreadName :: String
  -- ^ Label of the thread being forked.
  --
  -- Default: @"AutoUpdate"@
  --
  -- @since 0.1.0
  }

{- | Default value for creating an 'UpdateSettings'.

 @since 0.1.0
-}
defaultUpdateSettings :: UpdateSettings Identity ()
defaultUpdateSettings :: UpdateSettings Identity ()
defaultUpdateSettings =
  UpdateSettings
    { updateFreq :: Int
updateFreq = Int
1000000
    , updateSpawnThreshold :: Int
updateSpawnThreshold = Int
3
    , updateAction :: Identity ()
updateAction = forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
    , updateThreadName :: String
updateThreadName = String
"AutoUpdate"
    }