{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# LANGUAGE NoImplicitPrelude #-}

-- | SDL power management routines.
--
--     There is a single function in this category: @SDL_GetPowerInfo()@.
--
--     This function is useful for games on the go. This allows an app to know if it\'s running on a draining battery, which can be useful if the app wants to reduce processing, or perhaps framerate, to extend the duration of the battery\'s charge. Perhaps the app just wants to show a battery meter when fullscreen, or alert the user when the power is getting extremely low, so they can save their game. The basic state for the system\'s power supply.
--
--     These are results returned by @SDL_GetPowerInfo()@.
--
--     @since 3.2.0
module SDL3.Sys.Bindgen.Power (
  SDL3.Sys.Bindgen.Power.SDL_PowerState (..),
  pattern SDL3.Sys.Bindgen.Power.SDL_POWERSTATE_ERROR,
  pattern SDL3.Sys.Bindgen.Power.SDL_POWERSTATE_UNKNOWN,
  pattern SDL3.Sys.Bindgen.Power.SDL_POWERSTATE_ON_BATTERY,
  pattern SDL3.Sys.Bindgen.Power.SDL_POWERSTATE_NO_BATTERY,
  pattern SDL3.Sys.Bindgen.Power.SDL_POWERSTATE_CHARGING,
  pattern SDL3.Sys.Bindgen.Power.SDL_POWERSTATE_CHARGED,
)
where

import Prelude (Eq, Int, Ord, Read, Show, pure, (<*>), type (~))

import HsBindgen.Runtime.CEnum qualified as CEnum
import HsBindgen.Runtime.HasCField qualified as HasCField
import HsBindgen.Runtime.Marshal qualified as Marshal
import HsBindgen.Runtime.Support qualified as BG
import HsBindgen.Runtime.Support.CompatHasField qualified as BG.CompatHasField

-- | [C declaration]: @enum SDL_PowerState@, defined at @SDL3\/SDL_power.h 56:14@
newtype SDL_PowerState = SDL_PowerState
  { SDL_PowerState -> CInt
unwrap :: BG.CInt
  }
  deriving stock ((forall x. SDL_PowerState -> Rep SDL_PowerState x)
-> (forall x. Rep SDL_PowerState x -> SDL_PowerState)
-> Generic SDL_PowerState
forall x. Rep SDL_PowerState x -> SDL_PowerState
forall x. SDL_PowerState -> Rep SDL_PowerState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SDL_PowerState -> Rep SDL_PowerState x
from :: forall x. SDL_PowerState -> Rep SDL_PowerState x
$cto :: forall x. Rep SDL_PowerState x -> SDL_PowerState
to :: forall x. Rep SDL_PowerState x -> SDL_PowerState
BG.Generic, SDL_PowerState -> SDL_PowerState -> Bool
(SDL_PowerState -> SDL_PowerState -> Bool)
-> (SDL_PowerState -> SDL_PowerState -> Bool) -> Eq SDL_PowerState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SDL_PowerState -> SDL_PowerState -> Bool
== :: SDL_PowerState -> SDL_PowerState -> Bool
$c/= :: SDL_PowerState -> SDL_PowerState -> Bool
/= :: SDL_PowerState -> SDL_PowerState -> Bool
Eq, Eq SDL_PowerState
Eq SDL_PowerState =>
(SDL_PowerState -> SDL_PowerState -> Ordering)
-> (SDL_PowerState -> SDL_PowerState -> Bool)
-> (SDL_PowerState -> SDL_PowerState -> Bool)
-> (SDL_PowerState -> SDL_PowerState -> Bool)
-> (SDL_PowerState -> SDL_PowerState -> Bool)
-> (SDL_PowerState -> SDL_PowerState -> SDL_PowerState)
-> (SDL_PowerState -> SDL_PowerState -> SDL_PowerState)
-> Ord SDL_PowerState
SDL_PowerState -> SDL_PowerState -> Bool
SDL_PowerState -> SDL_PowerState -> Ordering
SDL_PowerState -> SDL_PowerState -> SDL_PowerState
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SDL_PowerState -> SDL_PowerState -> Ordering
compare :: SDL_PowerState -> SDL_PowerState -> Ordering
$c< :: SDL_PowerState -> SDL_PowerState -> Bool
< :: SDL_PowerState -> SDL_PowerState -> Bool
$c<= :: SDL_PowerState -> SDL_PowerState -> Bool
<= :: SDL_PowerState -> SDL_PowerState -> Bool
$c> :: SDL_PowerState -> SDL_PowerState -> Bool
> :: SDL_PowerState -> SDL_PowerState -> Bool
$c>= :: SDL_PowerState -> SDL_PowerState -> Bool
>= :: SDL_PowerState -> SDL_PowerState -> Bool
$cmax :: SDL_PowerState -> SDL_PowerState -> SDL_PowerState
max :: SDL_PowerState -> SDL_PowerState -> SDL_PowerState
$cmin :: SDL_PowerState -> SDL_PowerState -> SDL_PowerState
min :: SDL_PowerState -> SDL_PowerState -> SDL_PowerState
Ord)
  deriving newtype (FFIType SDL_PowerState -> SDL_PowerState
SDL_PowerState -> FFIType SDL_PowerState
(SDL_PowerState -> FFIType SDL_PowerState)
-> (FFIType SDL_PowerState -> SDL_PowerState)
-> HasFFIType SDL_PowerState
forall a. (a -> FFIType a) -> (FFIType a -> a) -> HasFFIType a
$ctoFFIType :: SDL_PowerState -> FFIType SDL_PowerState
toFFIType :: SDL_PowerState -> FFIType SDL_PowerState
$cfromFFIType :: FFIType SDL_PowerState -> SDL_PowerState
fromFFIType :: FFIType SDL_PowerState -> SDL_PowerState
BG.HasFFIType)

instance Marshal.StaticSize SDL_PowerState where
  staticSizeOf :: Proxy SDL_PowerState -> Int
staticSizeOf = \Proxy SDL_PowerState
_ -> (Int
4 :: Int)

  staticAlignment :: Proxy SDL_PowerState -> Int
staticAlignment = \Proxy SDL_PowerState
_ -> (Int
4 :: Int)

instance Marshal.ReadRaw SDL_PowerState where
  readRaw :: Ptr SDL_PowerState -> IO SDL_PowerState
readRaw =
    \Ptr SDL_PowerState
ptr0 ->
      (CInt -> SDL_PowerState) -> IO (CInt -> SDL_PowerState)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CInt -> SDL_PowerState
SDL_PowerState
        IO (CInt -> SDL_PowerState) -> IO CInt -> IO SDL_PowerState
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ptr SDL_PowerState -> Int -> IO CInt
forall a b. ReadRaw a => Ptr b -> Int -> IO a
Marshal.readRawByteOff Ptr SDL_PowerState
ptr0 (Int
0 :: Int)

instance Marshal.WriteRaw SDL_PowerState where
  writeRaw :: Ptr SDL_PowerState -> SDL_PowerState -> IO ()
writeRaw =
    \Ptr SDL_PowerState
ptr0 ->
      \SDL_PowerState
s1 ->
        case SDL_PowerState
s1 of
          SDL_PowerState CInt
unwrap2 ->
            Ptr SDL_PowerState -> Int -> CInt -> IO ()
forall a b. WriteRaw a => Ptr b -> Int -> a -> IO ()
Marshal.writeRawByteOff Ptr SDL_PowerState
ptr0 (Int
0 :: Int) CInt
unwrap2

deriving via Marshal.EquivStorable SDL_PowerState instance BG.Storable SDL_PowerState

deriving via BG.CInt instance BG.Prim SDL_PowerState

instance CEnum.CEnum SDL_PowerState where
  type CEnumZ SDL_PowerState = BG.CInt

  toCEnum :: CEnumZ SDL_PowerState -> SDL_PowerState
toCEnum = CInt -> SDL_PowerState
CEnumZ SDL_PowerState -> SDL_PowerState
SDL_PowerState

  fromCEnum :: SDL_PowerState -> CEnumZ SDL_PowerState
fromCEnum = forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"unwrap"

  declaredValues :: forall (proxy :: * -> *).
proxy SDL_PowerState -> DeclaredValues SDL_PowerState
declaredValues =
    \proxy SDL_PowerState
_ ->
      [(CEnumZ SDL_PowerState, NonEmpty String)]
-> DeclaredValues SDL_PowerState
forall a.
Ord (CEnumZ a) =>
[(CEnumZ a, NonEmpty String)] -> DeclaredValues a
CEnum.declaredValuesFromList
        [ (-CInt
1, String -> NonEmpty String
forall a. a -> NonEmpty a
BG.singleton String
"SDL_POWERSTATE_ERROR")
        , (CInt
CEnumZ SDL_PowerState
0, String -> NonEmpty String
forall a. a -> NonEmpty a
BG.singleton String
"SDL_POWERSTATE_UNKNOWN")
        , (CInt
CEnumZ SDL_PowerState
1, String -> NonEmpty String
forall a. a -> NonEmpty a
BG.singleton String
"SDL_POWERSTATE_ON_BATTERY")
        , (CInt
CEnumZ SDL_PowerState
2, String -> NonEmpty String
forall a. a -> NonEmpty a
BG.singleton String
"SDL_POWERSTATE_NO_BATTERY")
        , (CInt
CEnumZ SDL_PowerState
3, String -> NonEmpty String
forall a. a -> NonEmpty a
BG.singleton String
"SDL_POWERSTATE_CHARGING")
        , (CInt
CEnumZ SDL_PowerState
4, String -> NonEmpty String
forall a. a -> NonEmpty a
BG.singleton String
"SDL_POWERSTATE_CHARGED")
        ]

  showsUndeclared :: forall (proxy :: * -> *).
proxy SDL_PowerState -> Int -> CEnumZ SDL_PowerState -> ShowS
showsUndeclared =
    String
-> proxy SDL_PowerState -> Int -> CEnumZ SDL_PowerState -> ShowS
forall a (proxy :: * -> *).
Show (CEnumZ a) =>
String -> proxy a -> Int -> CEnumZ a -> ShowS
CEnum.showsWrappedUndeclared String
"SDL_PowerState"

  readPrecUndeclared :: ReadPrec SDL_PowerState
readPrecUndeclared =
    String -> ReadPrec SDL_PowerState
forall a. (CEnum a, Read (CEnumZ a)) => String -> ReadPrec a
CEnum.readPrecWrappedUndeclared String
"SDL_PowerState"

  isDeclared :: SDL_PowerState -> Bool
isDeclared = SDL_PowerState -> Bool
forall a. SequentialCEnum a => a -> Bool
CEnum.seqIsDeclared

  mkDeclared :: CEnumZ SDL_PowerState -> Maybe SDL_PowerState
mkDeclared = CEnumZ SDL_PowerState -> Maybe SDL_PowerState
forall a. SequentialCEnum a => CEnumZ a -> Maybe a
CEnum.seqMkDeclared

instance CEnum.SequentialCEnum SDL_PowerState where
  minDeclaredValue :: SDL_PowerState
minDeclaredValue = SDL_PowerState
SDL_POWERSTATE_ERROR

  maxDeclaredValue :: SDL_PowerState
maxDeclaredValue = SDL_PowerState
SDL_POWERSTATE_CHARGED

instance Show SDL_PowerState where
  showsPrec :: Int -> SDL_PowerState -> ShowS
showsPrec = Int -> SDL_PowerState -> ShowS
forall a. CEnum a => Int -> a -> ShowS
CEnum.shows

instance Read SDL_PowerState where
  readPrec :: ReadPrec SDL_PowerState
readPrec = ReadPrec SDL_PowerState
forall a. CEnum a => ReadPrec a
CEnum.readPrec

  readList :: ReadS [SDL_PowerState]
readList = ReadS [SDL_PowerState]
forall a. Read a => ReadS [a]
BG.readListDefault

  readListPrec :: ReadPrec [SDL_PowerState]
readListPrec = ReadPrec [SDL_PowerState]
forall a. Read a => ReadPrec [a]
BG.readListPrecDefault

instance
  (ty ~ BG.CInt)
  => BG.CompatHasField.HasField "unwrap" SDL_PowerState ty
  where
  hasField :: SDL_PowerState -> (ty -> SDL_PowerState, ty)
hasField =
    \SDL_PowerState
x0 ->
      ( \ty
y1 ->
          SDL_PowerState{unwrap :: CInt
unwrap = ty
CInt
y1}
      , forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"unwrap" SDL_PowerState
x0
      )

instance
  (ty ~ BG.CInt)
  => BG.HasField "unwrap" (BG.Ptr SDL_PowerState) (BG.Ptr ty)
  where
  getField :: Ptr SDL_PowerState -> Ptr ty
getField = Proxy "unwrap"
-> Ptr SDL_PowerState -> Ptr (CFieldType SDL_PowerState "unwrap")
forall a (field :: Symbol).
HasCField a field =>
Proxy field -> Ptr a -> Ptr (CFieldType a field)
HasCField.fromPtr (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"unwrap")

instance HasCField.HasCField SDL_PowerState "unwrap" where
  type CFieldType SDL_PowerState "unwrap" = BG.CInt

  offset# :: Proxy# SDL_PowerState -> Proxy# "unwrap" -> Int
offset# = \Proxy# SDL_PowerState
_ -> \Proxy# "unwrap"
_ -> Int
0

-- | error determining power status
--
--     [C declaration]: @SDL_POWERSTATE_ERROR@, defined at @SDL3\/SDL_power.h 58:5@
pattern SDL_POWERSTATE_ERROR :: SDL_PowerState
pattern $mSDL_POWERSTATE_ERROR :: forall {r}. SDL_PowerState -> ((# #) -> r) -> ((# #) -> r) -> r
$bSDL_POWERSTATE_ERROR :: SDL_PowerState
SDL_POWERSTATE_ERROR = SDL_PowerState (-1)

-- | cannot determine power status
--
--     [C declaration]: @SDL_POWERSTATE_UNKNOWN@, defined at @SDL3\/SDL_power.h 59:5@
pattern SDL_POWERSTATE_UNKNOWN :: SDL_PowerState
pattern $mSDL_POWERSTATE_UNKNOWN :: forall {r}. SDL_PowerState -> ((# #) -> r) -> ((# #) -> r) -> r
$bSDL_POWERSTATE_UNKNOWN :: SDL_PowerState
SDL_POWERSTATE_UNKNOWN = SDL_PowerState 0

-- | Not plugged in, running on the battery
--
--     [C declaration]: @SDL_POWERSTATE_ON_BATTERY@, defined at @SDL3\/SDL_power.h 60:5@
pattern SDL_POWERSTATE_ON_BATTERY :: SDL_PowerState
pattern $mSDL_POWERSTATE_ON_BATTERY :: forall {r}. SDL_PowerState -> ((# #) -> r) -> ((# #) -> r) -> r
$bSDL_POWERSTATE_ON_BATTERY :: SDL_PowerState
SDL_POWERSTATE_ON_BATTERY = SDL_PowerState 1

-- | Plugged in, no battery available
--
--     [C declaration]: @SDL_POWERSTATE_NO_BATTERY@, defined at @SDL3\/SDL_power.h 61:5@
pattern SDL_POWERSTATE_NO_BATTERY :: SDL_PowerState
pattern $mSDL_POWERSTATE_NO_BATTERY :: forall {r}. SDL_PowerState -> ((# #) -> r) -> ((# #) -> r) -> r
$bSDL_POWERSTATE_NO_BATTERY :: SDL_PowerState
SDL_POWERSTATE_NO_BATTERY = SDL_PowerState 2

-- | Plugged in, charging battery
--
--     [C declaration]: @SDL_POWERSTATE_CHARGING@, defined at @SDL3\/SDL_power.h 62:5@
pattern SDL_POWERSTATE_CHARGING :: SDL_PowerState
pattern $mSDL_POWERSTATE_CHARGING :: forall {r}. SDL_PowerState -> ((# #) -> r) -> ((# #) -> r) -> r
$bSDL_POWERSTATE_CHARGING :: SDL_PowerState
SDL_POWERSTATE_CHARGING = SDL_PowerState 3

-- | Plugged in, battery charged
--
--     [C declaration]: @SDL_POWERSTATE_CHARGED@, defined at @SDL3\/SDL_power.h 63:5@
pattern SDL_POWERSTATE_CHARGED :: SDL_PowerState
pattern $mSDL_POWERSTATE_CHARGED :: forall {r}. SDL_PowerState -> ((# #) -> r) -> ((# #) -> r) -> r
$bSDL_POWERSTATE_CHARGED :: SDL_PowerState
SDL_POWERSTATE_CHARGED = SDL_PowerState 4