{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

module Bitcoin.Core.RPC.Control (
    stop,
    uptime,
) where

import Data.Proxy (Proxy (..))
import Data.Word (Word32)
import Servant.API ((:<|>) (..))

import Servant.Bitcoind (
    BitcoindClient,
    BitcoindEndpoint,
    C,
    CX,
    toBitcoindClient,
 )

type ControlRpc =
    BitcoindEndpoint "stop" CX
        :<|> BitcoindEndpoint "uptime" (C Word32)

-- | Request a graceful shutdown of Bitcoin Core.
stop :: BitcoindClient ()

-- | Returns the total uptime of the server (in seconds)
uptime :: BitcoindClient Word32
stop :: BitcoindClient ()
stop :<|> uptime :: BitcoindClient Word32
uptime = Proxy ControlRpc -> BitcoindClient () :<|> BitcoindClient Word32
forall x (p :: * -> *).
HasBitcoindClient x =>
p x -> TheBitcoindClient x
toBitcoindClient (Proxy ControlRpc -> BitcoindClient () :<|> BitcoindClient Word32)
-> Proxy ControlRpc -> BitcoindClient () :<|> BitcoindClient Word32
forall a b. (a -> b) -> a -> b
$ Proxy ControlRpc
forall k (t :: k). Proxy t
Proxy @ControlRpc