module WebDriverPreCore.BiDi.Capabilities
  ( Capabilities (..),
    Capability (..),
    ProxyConfiguration (..),
    SocksProxyConfiguration (..),
    UserPromptHandler (..),
    UserPromptHandlerType (..),
    CapabilitiesResult (..),
  )
where

import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), object, (.=))
import Data.Maybe (catMaybes)
import Data.Text (Text)
import Data.Vector (fromList)
import Data.Word (Word8)
import GHC.Generics (Generic)
import AesonUtils (opt, fromJSONCamelCase)
import Data.Aeson.Types (Parser)



-- | Capabilities Request
data Capabilities = MkCapabilities
  { Capabilities -> Maybe Capability
alwaysMatch :: Maybe Capability,
    Capabilities -> [Capability]
firstMatch :: [Capability]
  }
  deriving (Int -> Capabilities -> ShowS
[Capabilities] -> ShowS
Capabilities -> String
(Int -> Capabilities -> ShowS)
-> (Capabilities -> String)
-> ([Capabilities] -> ShowS)
-> Show Capabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Capabilities -> ShowS
showsPrec :: Int -> Capabilities -> ShowS
$cshow :: Capabilities -> String
show :: Capabilities -> String
$cshowList :: [Capabilities] -> ShowS
showList :: [Capabilities] -> ShowS
Show, Capabilities -> Capabilities -> Bool
(Capabilities -> Capabilities -> Bool)
-> (Capabilities -> Capabilities -> Bool) -> Eq Capabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Capabilities -> Capabilities -> Bool
== :: Capabilities -> Capabilities -> Bool
$c/= :: Capabilities -> Capabilities -> Bool
/= :: Capabilities -> Capabilities -> Bool
Eq, (forall x. Capabilities -> Rep Capabilities x)
-> (forall x. Rep Capabilities x -> Capabilities)
-> Generic Capabilities
forall x. Rep Capabilities x -> Capabilities
forall x. Capabilities -> Rep Capabilities x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Capabilities -> Rep Capabilities x
from :: forall x. Capabilities -> Rep Capabilities x
$cto :: forall x. Rep Capabilities x -> Capabilities
to :: forall x. Rep Capabilities x -> Capabilities
Generic)

instance ToJSON Capabilities where
  toJSON :: Capabilities -> Value
  toJSON :: Capabilities -> Value
toJSON MkCapabilities {Maybe Capability
alwaysMatch :: Capabilities -> Maybe Capability
alwaysMatch :: Maybe Capability
alwaysMatch, [Capability]
firstMatch :: Capabilities -> [Capability]
firstMatch :: [Capability]
firstMatch} =
    [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
      [ Key
"capabilities" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ([Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Key -> Maybe Capability -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"alwaysMatch" (Maybe Capability -> Maybe Pair) -> Maybe Capability -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Maybe Capability
alwaysMatch]),
        Key
"firstMatch" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Value
firstMatch'
      ]
    where
      firstMatch' :: Value
      firstMatch' :: Value
firstMatch' = Array -> Value
Array (Array -> Value) -> ([Value] -> Array) -> [Value] -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Value] -> Array
forall a. [a] -> Vector a
Data.Vector.fromList ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ Capability -> Value
forall a. ToJSON a => a -> Value
toJSON (Capability -> Value) -> [Capability] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Capability]
firstMatch

-- | Capability Request
data Capability = MkCapability
  { Capability -> Maybe Bool
acceptInsecureCerts :: Maybe Bool,
    Capability -> Maybe Text
browserName :: Maybe Text,
    Capability -> Maybe Text
browserVersion :: Maybe Text,
    -- Always true for BiDi
    Capability -> Bool
webSocketUrl :: Bool,
    Capability -> Maybe Text
platformName :: Maybe Text,
    Capability -> Maybe ProxyConfiguration
proxy :: Maybe ProxyConfiguration,
    Capability -> Maybe UserPromptHandler
unhandledPromptBehavior :: Maybe UserPromptHandler
  }
  deriving (Int -> Capability -> ShowS
[Capability] -> ShowS
Capability -> String
(Int -> Capability -> ShowS)
-> (Capability -> String)
-> ([Capability] -> ShowS)
-> Show Capability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Capability -> ShowS
showsPrec :: Int -> Capability -> ShowS
$cshow :: Capability -> String
show :: Capability -> String
$cshowList :: [Capability] -> ShowS
showList :: [Capability] -> ShowS
Show, Capability -> Capability -> Bool
(Capability -> Capability -> Bool)
-> (Capability -> Capability -> Bool) -> Eq Capability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Capability -> Capability -> Bool
== :: Capability -> Capability -> Bool
$c/= :: Capability -> Capability -> Bool
/= :: Capability -> Capability -> Bool
Eq, (forall x. Capability -> Rep Capability x)
-> (forall x. Rep Capability x -> Capability) -> Generic Capability
forall x. Rep Capability x -> Capability
forall x. Capability -> Rep Capability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Capability -> Rep Capability x
from :: forall x. Capability -> Rep Capability x
$cto :: forall x. Rep Capability x -> Capability
to :: forall x. Rep Capability x -> Capability
Generic)

instance ToJSON Capability

-- | Proxy Configuration
data ProxyConfiguration
  = AutodetectProxyConfiguration
  | DirectProxyConfiguration
  | ManualProxyConfiguration
      { ProxyConfiguration -> Maybe Text
httpProxy :: Maybe Text,
        ProxyConfiguration -> Maybe Text
sslProxy :: Maybe Text,
        ProxyConfiguration -> Maybe SocksProxyConfiguration
socksProxyConfig :: Maybe SocksProxyConfiguration,
        ProxyConfiguration -> Maybe [Text]
noProxy :: Maybe [Text]
      }
  | PacProxyConfiguration
      { ProxyConfiguration -> Text
proxyAutoconfigUrl :: Text
      }
  | SystemProxyConfiguration
  deriving (Int -> ProxyConfiguration -> ShowS
[ProxyConfiguration] -> ShowS
ProxyConfiguration -> String
(Int -> ProxyConfiguration -> ShowS)
-> (ProxyConfiguration -> String)
-> ([ProxyConfiguration] -> ShowS)
-> Show ProxyConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProxyConfiguration -> ShowS
showsPrec :: Int -> ProxyConfiguration -> ShowS
$cshow :: ProxyConfiguration -> String
show :: ProxyConfiguration -> String
$cshowList :: [ProxyConfiguration] -> ShowS
showList :: [ProxyConfiguration] -> ShowS
Show, ProxyConfiguration -> ProxyConfiguration -> Bool
(ProxyConfiguration -> ProxyConfiguration -> Bool)
-> (ProxyConfiguration -> ProxyConfiguration -> Bool)
-> Eq ProxyConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProxyConfiguration -> ProxyConfiguration -> Bool
== :: ProxyConfiguration -> ProxyConfiguration -> Bool
$c/= :: ProxyConfiguration -> ProxyConfiguration -> Bool
/= :: ProxyConfiguration -> ProxyConfiguration -> Bool
Eq, (forall x. ProxyConfiguration -> Rep ProxyConfiguration x)
-> (forall x. Rep ProxyConfiguration x -> ProxyConfiguration)
-> Generic ProxyConfiguration
forall x. Rep ProxyConfiguration x -> ProxyConfiguration
forall x. ProxyConfiguration -> Rep ProxyConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ProxyConfiguration -> Rep ProxyConfiguration x
from :: forall x. ProxyConfiguration -> Rep ProxyConfiguration x
$cto :: forall x. Rep ProxyConfiguration x -> ProxyConfiguration
to :: forall x. Rep ProxyConfiguration x -> ProxyConfiguration
Generic)

instance FromJSON ProxyConfiguration

instance ToJSON ProxyConfiguration where
  toJSON :: ProxyConfiguration -> Value
  toJSON :: ProxyConfiguration -> Value
toJSON = \case
    ProxyConfiguration
AutodetectProxyConfiguration -> [Pair] -> Value
object [Key
"proxyType" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"autodetect" :: Text)]
    ProxyConfiguration
DirectProxyConfiguration -> [Pair] -> Value
object [Key
"proxyType" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"direct" :: Text)]
    ManualProxyConfiguration {Maybe Text
httpProxy :: ProxyConfiguration -> Maybe Text
httpProxy :: Maybe Text
httpProxy, Maybe Text
sslProxy :: ProxyConfiguration -> Maybe Text
sslProxy :: Maybe Text
sslProxy, Maybe SocksProxyConfiguration
socksProxyConfig :: ProxyConfiguration -> Maybe SocksProxyConfiguration
socksProxyConfig :: Maybe SocksProxyConfiguration
socksProxyConfig, Maybe [Text]
noProxy :: ProxyConfiguration -> Maybe [Text]
noProxy :: Maybe [Text]
noProxy} ->
      [Pair] -> Value
object
        [ Key
"proxyType" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"manual" :: Text),
          Key
"httpProxy" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
httpProxy,
          Key
"sslProxy" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
sslProxy,
          Key
"socksProxy" Key -> Maybe SocksProxyConfiguration -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe SocksProxyConfiguration
socksProxyConfig,
          Key
"noProxy" Key -> Maybe [Text] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe [Text]
noProxy
        ]
    PacProxyConfiguration Text
proxyAutoconfigUrl ->
      [Pair] -> Value
object [Key
"proxyType" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"pac" :: Text), Key
"proxyAutoconfigUrl" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
proxyAutoconfigUrl]
    ProxyConfiguration
SystemProxyConfiguration -> [Pair] -> Value
object [Key
"proxyType" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"system" :: Text)]

instance FromJSON SocksProxyConfiguration

instance ToJSON SocksProxyConfiguration where
  toJSON :: SocksProxyConfiguration -> Value
  toJSON :: SocksProxyConfiguration -> Value
toJSON (MkSocksProxyConfiguration Text
socksProxy Word8
socksVersion) =
    [Pair] -> Value
object
      [ Key
"socksProxy" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
socksProxy,
        Key
"socksVersion" Key -> Word8 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word8
socksVersion
      ]

-- | Socks Proxy Configuration
data SocksProxyConfiguration = MkSocksProxyConfiguration
  { SocksProxyConfiguration -> Text
socksProxy :: Text,
    SocksProxyConfiguration -> Word8
socksVersion :: Word8
  }
  deriving (Int -> SocksProxyConfiguration -> ShowS
[SocksProxyConfiguration] -> ShowS
SocksProxyConfiguration -> String
(Int -> SocksProxyConfiguration -> ShowS)
-> (SocksProxyConfiguration -> String)
-> ([SocksProxyConfiguration] -> ShowS)
-> Show SocksProxyConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SocksProxyConfiguration -> ShowS
showsPrec :: Int -> SocksProxyConfiguration -> ShowS
$cshow :: SocksProxyConfiguration -> String
show :: SocksProxyConfiguration -> String
$cshowList :: [SocksProxyConfiguration] -> ShowS
showList :: [SocksProxyConfiguration] -> ShowS
Show, SocksProxyConfiguration -> SocksProxyConfiguration -> Bool
(SocksProxyConfiguration -> SocksProxyConfiguration -> Bool)
-> (SocksProxyConfiguration -> SocksProxyConfiguration -> Bool)
-> Eq SocksProxyConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SocksProxyConfiguration -> SocksProxyConfiguration -> Bool
== :: SocksProxyConfiguration -> SocksProxyConfiguration -> Bool
$c/= :: SocksProxyConfiguration -> SocksProxyConfiguration -> Bool
/= :: SocksProxyConfiguration -> SocksProxyConfiguration -> Bool
Eq, (forall x.
 SocksProxyConfiguration -> Rep SocksProxyConfiguration x)
-> (forall x.
    Rep SocksProxyConfiguration x -> SocksProxyConfiguration)
-> Generic SocksProxyConfiguration
forall x. Rep SocksProxyConfiguration x -> SocksProxyConfiguration
forall x. SocksProxyConfiguration -> Rep SocksProxyConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SocksProxyConfiguration -> Rep SocksProxyConfiguration x
from :: forall x. SocksProxyConfiguration -> Rep SocksProxyConfiguration x
$cto :: forall x. Rep SocksProxyConfiguration x -> SocksProxyConfiguration
to :: forall x. Rep SocksProxyConfiguration x -> SocksProxyConfiguration
Generic)

-- | User Prompt Handler
data UserPromptHandler = MkUserPromptHandler
  { UserPromptHandler -> Maybe UserPromptHandlerType
alert :: Maybe UserPromptHandlerType,
    UserPromptHandler -> Maybe UserPromptHandlerType
beforeUnload :: Maybe UserPromptHandlerType,
    UserPromptHandler -> Maybe UserPromptHandlerType
confirm :: Maybe UserPromptHandlerType,
    UserPromptHandler -> Maybe UserPromptHandlerType
defaultHandler :: Maybe UserPromptHandlerType,
    UserPromptHandler -> Maybe UserPromptHandlerType
fileHandler :: Maybe UserPromptHandlerType,
    UserPromptHandler -> Maybe UserPromptHandlerType
prompt :: Maybe UserPromptHandlerType
  }
  deriving (Int -> UserPromptHandler -> ShowS
[UserPromptHandler] -> ShowS
UserPromptHandler -> String
(Int -> UserPromptHandler -> ShowS)
-> (UserPromptHandler -> String)
-> ([UserPromptHandler] -> ShowS)
-> Show UserPromptHandler
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserPromptHandler -> ShowS
showsPrec :: Int -> UserPromptHandler -> ShowS
$cshow :: UserPromptHandler -> String
show :: UserPromptHandler -> String
$cshowList :: [UserPromptHandler] -> ShowS
showList :: [UserPromptHandler] -> ShowS
Show, UserPromptHandler -> UserPromptHandler -> Bool
(UserPromptHandler -> UserPromptHandler -> Bool)
-> (UserPromptHandler -> UserPromptHandler -> Bool)
-> Eq UserPromptHandler
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserPromptHandler -> UserPromptHandler -> Bool
== :: UserPromptHandler -> UserPromptHandler -> Bool
$c/= :: UserPromptHandler -> UserPromptHandler -> Bool
/= :: UserPromptHandler -> UserPromptHandler -> Bool
Eq, (forall x. UserPromptHandler -> Rep UserPromptHandler x)
-> (forall x. Rep UserPromptHandler x -> UserPromptHandler)
-> Generic UserPromptHandler
forall x. Rep UserPromptHandler x -> UserPromptHandler
forall x. UserPromptHandler -> Rep UserPromptHandler x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. UserPromptHandler -> Rep UserPromptHandler x
from :: forall x. UserPromptHandler -> Rep UserPromptHandler x
$cto :: forall x. Rep UserPromptHandler x -> UserPromptHandler
to :: forall x. Rep UserPromptHandler x -> UserPromptHandler
Generic)

instance FromJSON UserPromptHandler

instance ToJSON UserPromptHandler where
  toJSON :: UserPromptHandler -> Value
  toJSON :: UserPromptHandler -> Value
toJSON (MkUserPromptHandler Maybe UserPromptHandlerType
alert Maybe UserPromptHandlerType
beforeUnload Maybe UserPromptHandlerType
confirm Maybe UserPromptHandlerType
defaultHandler Maybe UserPromptHandlerType
fileHandler Maybe UserPromptHandlerType
prompt) =
    [Pair] -> Value
object
      [ Key
"alert" Key -> Maybe UserPromptHandlerType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe UserPromptHandlerType
alert,
        Key
"beforeUnload" Key -> Maybe UserPromptHandlerType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe UserPromptHandlerType
beforeUnload,
        Key
"confirm" Key -> Maybe UserPromptHandlerType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe UserPromptHandlerType
confirm,
        Key
"defaultHandler" Key -> Maybe UserPromptHandlerType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe UserPromptHandlerType
defaultHandler,
        Key
"fileHandler" Key -> Maybe UserPromptHandlerType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe UserPromptHandlerType
fileHandler,
        Key
"prompt" Key -> Maybe UserPromptHandlerType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe UserPromptHandlerType
prompt
      ]

-- | User Prompt Handler Type
data UserPromptHandlerType
  = Accept
  | Dismiss
  | Ignore
  deriving (Int -> UserPromptHandlerType -> ShowS
[UserPromptHandlerType] -> ShowS
UserPromptHandlerType -> String
(Int -> UserPromptHandlerType -> ShowS)
-> (UserPromptHandlerType -> String)
-> ([UserPromptHandlerType] -> ShowS)
-> Show UserPromptHandlerType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserPromptHandlerType -> ShowS
showsPrec :: Int -> UserPromptHandlerType -> ShowS
$cshow :: UserPromptHandlerType -> String
show :: UserPromptHandlerType -> String
$cshowList :: [UserPromptHandlerType] -> ShowS
showList :: [UserPromptHandlerType] -> ShowS
Show, UserPromptHandlerType -> UserPromptHandlerType -> Bool
(UserPromptHandlerType -> UserPromptHandlerType -> Bool)
-> (UserPromptHandlerType -> UserPromptHandlerType -> Bool)
-> Eq UserPromptHandlerType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserPromptHandlerType -> UserPromptHandlerType -> Bool
== :: UserPromptHandlerType -> UserPromptHandlerType -> Bool
$c/= :: UserPromptHandlerType -> UserPromptHandlerType -> Bool
/= :: UserPromptHandlerType -> UserPromptHandlerType -> Bool
Eq, (forall x. UserPromptHandlerType -> Rep UserPromptHandlerType x)
-> (forall x. Rep UserPromptHandlerType x -> UserPromptHandlerType)
-> Generic UserPromptHandlerType
forall x. Rep UserPromptHandlerType x -> UserPromptHandlerType
forall x. UserPromptHandlerType -> Rep UserPromptHandlerType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. UserPromptHandlerType -> Rep UserPromptHandlerType x
from :: forall x. UserPromptHandlerType -> Rep UserPromptHandlerType x
$cto :: forall x. Rep UserPromptHandlerType x -> UserPromptHandlerType
to :: forall x. Rep UserPromptHandlerType x -> UserPromptHandlerType
Generic)

instance FromJSON UserPromptHandlerType where
  parseJSON :: Value -> Parser UserPromptHandlerType
  parseJSON :: Value -> Parser UserPromptHandlerType
parseJSON = Value -> Parser UserPromptHandlerType
forall a. (Generic a, GFromJSON Zero (Rep a)) => Value -> Parser a
fromJSONCamelCase

instance ToJSON UserPromptHandlerType where
  toJSON :: UserPromptHandlerType -> Value
  toJSON :: UserPromptHandlerType -> Value
toJSON = \case
    UserPromptHandlerType
Accept -> Value
"accept"
    UserPromptHandlerType
Dismiss -> Value
"dismiss"
    UserPromptHandlerType
Ignore -> Value
"ignore"


-- | Capabilities Result
data CapabilitiesResult = MkCapabilitiesResult
  { CapabilitiesResult -> Bool
acceptInsecureCerts :: Bool,
    CapabilitiesResult -> Text
browserName :: Text,
    CapabilitiesResult -> Text
browserVersion :: Text,
    CapabilitiesResult -> Text
platformName :: Text,
    CapabilitiesResult -> Bool
setWindowRect :: Bool,
    CapabilitiesResult -> Text
userAgent :: Text,
    CapabilitiesResult -> Maybe ProxyConfiguration
proxy :: Maybe ProxyConfiguration,
    CapabilitiesResult -> Maybe UserPromptHandler
unhandledPromptBehavior :: Maybe UserPromptHandler,
    CapabilitiesResult -> Maybe Text
webSocketUrl :: Maybe Text
  }
  deriving (Int -> CapabilitiesResult -> ShowS
[CapabilitiesResult] -> ShowS
CapabilitiesResult -> String
(Int -> CapabilitiesResult -> ShowS)
-> (CapabilitiesResult -> String)
-> ([CapabilitiesResult] -> ShowS)
-> Show CapabilitiesResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CapabilitiesResult -> ShowS
showsPrec :: Int -> CapabilitiesResult -> ShowS
$cshow :: CapabilitiesResult -> String
show :: CapabilitiesResult -> String
$cshowList :: [CapabilitiesResult] -> ShowS
showList :: [CapabilitiesResult] -> ShowS
Show, CapabilitiesResult -> CapabilitiesResult -> Bool
(CapabilitiesResult -> CapabilitiesResult -> Bool)
-> (CapabilitiesResult -> CapabilitiesResult -> Bool)
-> Eq CapabilitiesResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CapabilitiesResult -> CapabilitiesResult -> Bool
== :: CapabilitiesResult -> CapabilitiesResult -> Bool
$c/= :: CapabilitiesResult -> CapabilitiesResult -> Bool
/= :: CapabilitiesResult -> CapabilitiesResult -> Bool
Eq, (forall x. CapabilitiesResult -> Rep CapabilitiesResult x)
-> (forall x. Rep CapabilitiesResult x -> CapabilitiesResult)
-> Generic CapabilitiesResult
forall x. Rep CapabilitiesResult x -> CapabilitiesResult
forall x. CapabilitiesResult -> Rep CapabilitiesResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CapabilitiesResult -> Rep CapabilitiesResult x
from :: forall x. CapabilitiesResult -> Rep CapabilitiesResult x
$cto :: forall x. Rep CapabilitiesResult x -> CapabilitiesResult
to :: forall x. Rep CapabilitiesResult x -> CapabilitiesResult
Generic)

instance ToJSON CapabilitiesResult where
  toJSON :: CapabilitiesResult -> Value
  toJSON :: CapabilitiesResult -> Value
toJSON (MkCapabilitiesResult Bool
acceptInsecureCerts Text
browserName Text
browserVersion Text
platformName Bool
setWindowRect Text
userAgent Maybe ProxyConfiguration
proxy Maybe UserPromptHandler
unhandledPromptBehavior Maybe Text
webSocketUrl) =
    [Pair] -> Value
object
      [ Key
"acceptInsecureCerts" Key -> Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Bool
acceptInsecureCerts,
        Key
"browserName" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
browserName,
        Key
"browserVersion" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
browserVersion,
        Key
"platformName" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
platformName,
        Key
"setWindowRect" Key -> Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Bool
setWindowRect,
        Key
"userAgent" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
userAgent,
        Key
"proxy" Key -> Maybe ProxyConfiguration -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe ProxyConfiguration
proxy,
        Key
"unhandledPromptBehavior" Key -> Maybe UserPromptHandler -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe UserPromptHandler
unhandledPromptBehavior,
        Key
"webSocketUrl" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
webSocketUrl
      ]

instance FromJSON CapabilitiesResult