module Cardano.CLI.EraIndependent.Ping.Command
  ( EndPoint (..)
  , PingCmd (..)
  , getConfigurationError
  )
where

import Data.Word

data EndPoint
  = HostEndPoint String
  | UnixSockEndPoint String
  deriving (EndPoint -> EndPoint -> Bool
(EndPoint -> EndPoint -> Bool)
-> (EndPoint -> EndPoint -> Bool) -> Eq EndPoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EndPoint -> EndPoint -> Bool
== :: EndPoint -> EndPoint -> Bool
$c/= :: EndPoint -> EndPoint -> Bool
/= :: EndPoint -> EndPoint -> Bool
Eq, Int -> EndPoint -> ShowS
[EndPoint] -> ShowS
EndPoint -> [Char]
(Int -> EndPoint -> ShowS)
-> (EndPoint -> [Char]) -> ([EndPoint] -> ShowS) -> Show EndPoint
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EndPoint -> ShowS
showsPrec :: Int -> EndPoint -> ShowS
$cshow :: EndPoint -> [Char]
show :: EndPoint -> [Char]
$cshowList :: [EndPoint] -> ShowS
showList :: [EndPoint] -> ShowS
Show)

data PingCmd = PingCmd
  { PingCmd -> Word32
pingCmdCount :: !Word32
  , PingCmd -> EndPoint
pingCmdEndPoint :: !EndPoint
  , PingCmd -> [Char]
pingCmdPort :: !String
  , PingCmd -> Word32
pingCmdMagic :: !Word32
  , PingCmd -> Bool
pingCmdJson :: !Bool
  , PingCmd -> Bool
pingCmdQuiet :: !Bool
  , PingCmd -> Bool
pingOptsHandshakeQuery :: !Bool
  , PingCmd -> Bool
pingOptsGetTip :: !Bool
  }
  deriving (PingCmd -> PingCmd -> Bool
(PingCmd -> PingCmd -> Bool)
-> (PingCmd -> PingCmd -> Bool) -> Eq PingCmd
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PingCmd -> PingCmd -> Bool
== :: PingCmd -> PingCmd -> Bool
$c/= :: PingCmd -> PingCmd -> Bool
/= :: PingCmd -> PingCmd -> Bool
Eq, Int -> PingCmd -> ShowS
[PingCmd] -> ShowS
PingCmd -> [Char]
(Int -> PingCmd -> ShowS)
-> (PingCmd -> [Char]) -> ([PingCmd] -> ShowS) -> Show PingCmd
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PingCmd -> ShowS
showsPrec :: Int -> PingCmd -> ShowS
$cshow :: PingCmd -> [Char]
show :: PingCmd -> [Char]
$cshowList :: [PingCmd] -> ShowS
showList :: [PingCmd] -> ShowS
Show)

getConfigurationError :: PingCmd -> Maybe String
getConfigurationError :: PingCmd -> Maybe [Char]
getConfigurationError
  PingCmd
    { pingCmdEndPoint :: PingCmd -> EndPoint
pingCmdEndPoint = EndPoint
endPoint
    , pingOptsGetTip :: PingCmd -> Bool
pingOptsGetTip = Bool
getTip
    , pingOptsHandshakeQuery :: PingCmd -> Bool
pingOptsHandshakeQuery = Bool
query
    } =
    case EndPoint
endPoint of
      UnixSockEndPoint{}
        | Bool
query Bool -> Bool -> Bool
|| Bool
getTip -> Maybe [Char]
forall a. Maybe a
Nothing
        | Bool
otherwise -> [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just [Char]
"Unix sockets only support queries for available versions or a tip."
      HostEndPoint{} -> Maybe [Char]
forall a. Maybe a
Nothing