module Test.Marionette.Element where

import Data.Aeson.Types
import Data.Hashable (Hashable)
import Data.Text (Text)
import Prelude

-- | An opaque identifier for a web page element.
newtype Element = Element {Element -> Text
elementId :: Text}
    deriving newtype
        ( Element -> Element -> Bool
(Element -> Element -> Bool)
-> (Element -> Element -> Bool) -> Eq Element
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Element -> Element -> Bool
== :: Element -> Element -> Bool
$c/= :: Element -> Element -> Bool
/= :: Element -> Element -> Bool
Eq
        , Eq Element
Eq Element =>
(Element -> Element -> Ordering)
-> (Element -> Element -> Bool)
-> (Element -> Element -> Bool)
-> (Element -> Element -> Bool)
-> (Element -> Element -> Bool)
-> (Element -> Element -> Element)
-> (Element -> Element -> Element)
-> Ord Element
Element -> Element -> Bool
Element -> Element -> Ordering
Element -> Element -> Element
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 :: Element -> Element -> Ordering
compare :: Element -> Element -> Ordering
$c< :: Element -> Element -> Bool
< :: Element -> Element -> Bool
$c<= :: Element -> Element -> Bool
<= :: Element -> Element -> Bool
$c> :: Element -> Element -> Bool
> :: Element -> Element -> Bool
$c>= :: Element -> Element -> Bool
>= :: Element -> Element -> Bool
$cmax :: Element -> Element -> Element
max :: Element -> Element -> Element
$cmin :: Element -> Element -> Element
min :: Element -> Element -> Element
Ord
        , Int -> Element -> ShowS
[Element] -> ShowS
Element -> String
(Int -> Element -> ShowS)
-> (Element -> String) -> ([Element] -> ShowS) -> Show Element
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Element -> ShowS
showsPrec :: Int -> Element -> ShowS
$cshow :: Element -> String
show :: Element -> String
$cshowList :: [Element] -> ShowS
showList :: [Element] -> ShowS
Show
        , ReadPrec [Element]
ReadPrec Element
Int -> ReadS Element
ReadS [Element]
(Int -> ReadS Element)
-> ReadS [Element]
-> ReadPrec Element
-> ReadPrec [Element]
-> Read Element
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Element
readsPrec :: Int -> ReadS Element
$creadList :: ReadS [Element]
readList :: ReadS [Element]
$creadPrec :: ReadPrec Element
readPrec :: ReadPrec Element
$creadListPrec :: ReadPrec [Element]
readListPrec :: ReadPrec [Element]
Read
        , Eq Element
Eq Element =>
(Int -> Element -> Int) -> (Element -> Int) -> Hashable Element
Int -> Element -> Int
Element -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> Element -> Int
hashWithSalt :: Int -> Element -> Int
$chash :: Element -> Int
hash :: Element -> Int
Hashable
        )

instance FromJSON Element where
    parseJSON :: Value -> Parser Element
parseJSON = String -> (Object -> Parser Element) -> Value -> Parser Element
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Element" \Object
o -> do
        Text
elementId <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"element-6066-11e4-a52e-4f735466cecf"
        pure Element{Text
elementId :: Text
elementId :: Text
..}

instance ToJSON Element where
    toJSON :: Element -> Value
toJSON Element{Text
elementId :: Element -> Text
elementId :: Text
..} = [Pair] -> Value
object [Key
"element-6066-11e4-a52e-4f735466cecf" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]

-- | An opaque identifier for a web page element that identifies a shadow root.
newtype Shadow = Shadow {Shadow -> Text
shadowId :: Text}
    deriving newtype
        ( Shadow -> Shadow -> Bool
(Shadow -> Shadow -> Bool)
-> (Shadow -> Shadow -> Bool) -> Eq Shadow
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Shadow -> Shadow -> Bool
== :: Shadow -> Shadow -> Bool
$c/= :: Shadow -> Shadow -> Bool
/= :: Shadow -> Shadow -> Bool
Eq
        , Eq Shadow
Eq Shadow =>
(Shadow -> Shadow -> Ordering)
-> (Shadow -> Shadow -> Bool)
-> (Shadow -> Shadow -> Bool)
-> (Shadow -> Shadow -> Bool)
-> (Shadow -> Shadow -> Bool)
-> (Shadow -> Shadow -> Shadow)
-> (Shadow -> Shadow -> Shadow)
-> Ord Shadow
Shadow -> Shadow -> Bool
Shadow -> Shadow -> Ordering
Shadow -> Shadow -> Shadow
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 :: Shadow -> Shadow -> Ordering
compare :: Shadow -> Shadow -> Ordering
$c< :: Shadow -> Shadow -> Bool
< :: Shadow -> Shadow -> Bool
$c<= :: Shadow -> Shadow -> Bool
<= :: Shadow -> Shadow -> Bool
$c> :: Shadow -> Shadow -> Bool
> :: Shadow -> Shadow -> Bool
$c>= :: Shadow -> Shadow -> Bool
>= :: Shadow -> Shadow -> Bool
$cmax :: Shadow -> Shadow -> Shadow
max :: Shadow -> Shadow -> Shadow
$cmin :: Shadow -> Shadow -> Shadow
min :: Shadow -> Shadow -> Shadow
Ord
        , Int -> Shadow -> ShowS
[Shadow] -> ShowS
Shadow -> String
(Int -> Shadow -> ShowS)
-> (Shadow -> String) -> ([Shadow] -> ShowS) -> Show Shadow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Shadow -> ShowS
showsPrec :: Int -> Shadow -> ShowS
$cshow :: Shadow -> String
show :: Shadow -> String
$cshowList :: [Shadow] -> ShowS
showList :: [Shadow] -> ShowS
Show
        , ReadPrec [Shadow]
ReadPrec Shadow
Int -> ReadS Shadow
ReadS [Shadow]
(Int -> ReadS Shadow)
-> ReadS [Shadow]
-> ReadPrec Shadow
-> ReadPrec [Shadow]
-> Read Shadow
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Shadow
readsPrec :: Int -> ReadS Shadow
$creadList :: ReadS [Shadow]
readList :: ReadS [Shadow]
$creadPrec :: ReadPrec Shadow
readPrec :: ReadPrec Shadow
$creadListPrec :: ReadPrec [Shadow]
readListPrec :: ReadPrec [Shadow]
Read
        , Eq Shadow
Eq Shadow =>
(Int -> Shadow -> Int) -> (Shadow -> Int) -> Hashable Shadow
Int -> Shadow -> Int
Shadow -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> Shadow -> Int
hashWithSalt :: Int -> Shadow -> Int
$chash :: Shadow -> Int
hash :: Shadow -> Int
Hashable
        )

instance FromJSON Shadow where
    parseJSON :: Value -> Parser Shadow
parseJSON = String -> (Object -> Parser Shadow) -> Value -> Parser Shadow
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Element" \Object
o -> do
        Text
shadowId <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"shadow-6066-11e4-a52e-4f735466cecf"
        pure Shadow{Text
shadowId :: Text
shadowId :: Text
..}

instance ToJSON Shadow where
    toJSON :: Shadow -> Value
toJSON Shadow{Text
shadowId :: Shadow -> Text
shadowId :: Text
..} = [Pair] -> Value
object [Key
"shadow-6066-11e4-a52e-4f735466cecf" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
shadowId]