{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}

-- | This module provides toml configuration for the battery status service.
module Navi.Services.Battery.Status.Toml
  ( BatteryStatusToml (..),
  )
where

import Navi.Data.NaviNote (Timeout, timeoutOptDecoder)
import Navi.Data.PollInterval (PollInterval (..), pollIntervalOptDecoder)
import Navi.Event.Toml
  ( ErrorNoteToml,
    RepeatEventToml,
    errorNoteOptDecoder,
    repeatEventOptDecoder,
  )
import Navi.Prelude
import Navi.Services.Battery.Common (batteryAppDecoder)
import Pythia.Services.Battery (BatteryApp (..))

-- | TOML for the battery status service.
data BatteryStatusToml = MkBatteryStatusToml
  { -- | Determines how we should query the system for battery information.
    BatteryStatusToml -> BatteryApp
app :: BatteryApp,
    -- | The poll interval.
    BatteryStatusToml -> Maybe PollInterval
pollInterval :: Maybe PollInterval,
    -- | Determines how we treat repeat alerts.
    BatteryStatusToml -> Maybe RepeatEventToml
repeatEvent :: Maybe RepeatEventToml,
    -- | Determines how we handle errors.
    BatteryStatusToml -> Maybe ErrorNoteToml
errorNote :: Maybe ErrorNoteToml,
    -- | The timeout for this alert.
    BatteryStatusToml -> Maybe Timeout
mTimeout :: Maybe Timeout
  }
  deriving stock (BatteryStatusToml -> BatteryStatusToml -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatteryStatusToml -> BatteryStatusToml -> Bool
$c/= :: BatteryStatusToml -> BatteryStatusToml -> Bool
== :: BatteryStatusToml -> BatteryStatusToml -> Bool
$c== :: BatteryStatusToml -> BatteryStatusToml -> Bool
Eq, Int -> BatteryStatusToml -> ShowS
[BatteryStatusToml] -> ShowS
BatteryStatusToml -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatteryStatusToml] -> ShowS
$cshowList :: [BatteryStatusToml] -> ShowS
show :: BatteryStatusToml -> String
$cshow :: BatteryStatusToml -> String
showsPrec :: Int -> BatteryStatusToml -> ShowS
$cshowsPrec :: Int -> BatteryStatusToml -> ShowS
Show)

makeFieldLabelsNoPrefix ''BatteryStatusToml

-- | @since 0.1
instance DecodeTOML BatteryStatusToml where
  tomlDecoder :: Decoder BatteryStatusToml
tomlDecoder =
    BatteryApp
-> Maybe PollInterval
-> Maybe RepeatEventToml
-> Maybe ErrorNoteToml
-> Maybe Timeout
-> BatteryStatusToml
MkBatteryStatusToml
      forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Decoder a -> Text -> Decoder a
getFieldWith Decoder BatteryApp
batteryAppDecoder Text
"app"
      forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Decoder (Maybe PollInterval)
pollIntervalOptDecoder
      forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Decoder (Maybe RepeatEventToml)
repeatEventOptDecoder
      forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Decoder (Maybe ErrorNoteToml)
errorNoteOptDecoder
      forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Decoder (Maybe Timeout)
timeoutOptDecoder