module Cardano.CLI.Commands.Ping
  ( 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 -> String
(Int -> EndPoint -> ShowS)
-> (EndPoint -> String) -> ([EndPoint] -> ShowS) -> Show EndPoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EndPoint -> ShowS
showsPrec :: Int -> EndPoint -> ShowS
$cshow :: EndPoint -> String
show :: EndPoint -> String
$cshowList :: [EndPoint] -> ShowS
showList :: [EndPoint] -> ShowS
Show)

data PingCmd = PingCmd
  { PingCmd -> Word32
pingCmdCount :: !Word32
  , PingCmd -> EndPoint
pingCmdEndPoint :: !EndPoint
  , PingCmd -> String
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 -> String
(Int -> PingCmd -> ShowS)
-> (PingCmd -> String) -> ([PingCmd] -> ShowS) -> Show PingCmd
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PingCmd -> ShowS
showsPrec :: Int -> PingCmd -> ShowS
$cshow :: PingCmd -> String
show :: PingCmd -> String
$cshowList :: [PingCmd] -> ShowS
showList :: [PingCmd] -> ShowS
Show)

getConfigurationError :: PingCmd -> Maybe String
getConfigurationError :: PingCmd -> Maybe String
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 String
forall a. Maybe a
Nothing
        | Bool
otherwise -> String -> Maybe String
forall a. a -> Maybe a
Just String
"Unix sockets only support queries for available versions or a tip."
      HostEndPoint{} -> Maybe String
forall a. Maybe a
Nothing