-- | Provides common functionality for battery services.
module Navi.Services.Battery.Common
  ( batteryAppDecoder,
  )
where

import Navi.Prelude
import Pythia.Services.Battery (BatteryApp (..))

-- | TOML decoder for 'BatteryApp'.
--
-- @since 0.1
batteryAppDecoder :: Decoder BatteryApp
batteryAppDecoder :: Decoder BatteryApp
batteryAppDecoder =
  forall a. DecodeTOML a => Decoder a
tomlDecoder forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    Text
"acpi" -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure BatteryApp
BatteryAppAcpi
    Text
"sysfs" -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure BatteryApp
BatteryAppSysFs
    Text
"upower" -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure BatteryApp
BatteryAppUPower
    Text
bad ->
      forall (m :: Type -> Type) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$
        Text -> String
unpack forall a b. (a -> b) -> a -> b
$
          [Text] -> Text
concat
            [ Text
"Unexpected battery app: ",
              Text
bad,
              Text
". Expected one of <acpi | sysfs | upower>."
            ]
{-# INLINEABLE batteryAppDecoder #-}