{-# LANGUAGE DeriveAnyClass #-}

module WebDriverPreCore.BiDi.Storage
  ( PartitionKey (..),
    GetCookiesResult (..),
    SetCookieResult (..),
    DeleteCookiesResult (..),
    GetCookies (..),
    CookieFilter (..),
    PartitionDescriptor (..),
    SetCookie (..),
    PartialCookie (..),
    DeleteCookies (..),
  )
where

{-
create types to represent the remote and local end for storage:

1. preface singleton data constructors (ie the constructor for types with only one type constructor) with Mk
2. use newtypes where possible
3. ordering - order types such that types that are used by a type are declared immediately below that type in the order they are used
4. derive Show, Eq and Generic for all types
5. use Text rather than String
5. use the cddl in this file remote first under the -- ######### Remote ######### header
  then local under the -- ######### Local ######### header
7. Avoid using Parameters suffix in type and data constructor names
8. leave this comment at the top of the file
-}

import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), object, withObject, (.:), (.=))
import Data.Aeson.Types (Parser)
import Data.Maybe (catMaybes)
import Data.Text (Text)
import GHC.Generics (Generic)
import WebDriverPreCore.BiDi.CoreTypes (BrowsingContext, UserContext)
import WebDriverPreCore.BiDi.Network qualified as Network
import AesonUtils (fromJSONCamelCase, opt, toJSONOmitNothing)

-- ######### Remote #########

-- | Partition key for storage operations
data PartitionKey = MkPartitionKey
  { PartitionKey -> Maybe Text
userContext :: Maybe Text,
    PartitionKey -> Maybe Text
sourceOrigin :: Maybe Text
  }
  deriving (Int -> PartitionKey -> ShowS
[PartitionKey] -> ShowS
PartitionKey -> String
(Int -> PartitionKey -> ShowS)
-> (PartitionKey -> String)
-> ([PartitionKey] -> ShowS)
-> Show PartitionKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PartitionKey -> ShowS
showsPrec :: Int -> PartitionKey -> ShowS
$cshow :: PartitionKey -> String
show :: PartitionKey -> String
$cshowList :: [PartitionKey] -> ShowS
showList :: [PartitionKey] -> ShowS
Show, PartitionKey -> PartitionKey -> Bool
(PartitionKey -> PartitionKey -> Bool)
-> (PartitionKey -> PartitionKey -> Bool) -> Eq PartitionKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PartitionKey -> PartitionKey -> Bool
== :: PartitionKey -> PartitionKey -> Bool
$c/= :: PartitionKey -> PartitionKey -> Bool
/= :: PartitionKey -> PartitionKey -> Bool
Eq, (forall x. PartitionKey -> Rep PartitionKey x)
-> (forall x. Rep PartitionKey x -> PartitionKey)
-> Generic PartitionKey
forall x. Rep PartitionKey x -> PartitionKey
forall x. PartitionKey -> Rep PartitionKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PartitionKey -> Rep PartitionKey x
from :: forall x. PartitionKey -> Rep PartitionKey x
$cto :: forall x. Rep PartitionKey x -> PartitionKey
to :: forall x. Rep PartitionKey x -> PartitionKey
Generic)

instance FromJSON PartitionKey

instance ToJSON PartitionKey

-- | Result of getting cookies
data GetCookiesResult = MkGetCookiesResult
  { GetCookiesResult -> [Cookie]
cookies :: [Network.Cookie],
    GetCookiesResult -> PartitionKey
partitionKey :: PartitionKey
  }
  deriving (Int -> GetCookiesResult -> ShowS
[GetCookiesResult] -> ShowS
GetCookiesResult -> String
(Int -> GetCookiesResult -> ShowS)
-> (GetCookiesResult -> String)
-> ([GetCookiesResult] -> ShowS)
-> Show GetCookiesResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetCookiesResult -> ShowS
showsPrec :: Int -> GetCookiesResult -> ShowS
$cshow :: GetCookiesResult -> String
show :: GetCookiesResult -> String
$cshowList :: [GetCookiesResult] -> ShowS
showList :: [GetCookiesResult] -> ShowS
Show, GetCookiesResult -> GetCookiesResult -> Bool
(GetCookiesResult -> GetCookiesResult -> Bool)
-> (GetCookiesResult -> GetCookiesResult -> Bool)
-> Eq GetCookiesResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetCookiesResult -> GetCookiesResult -> Bool
== :: GetCookiesResult -> GetCookiesResult -> Bool
$c/= :: GetCookiesResult -> GetCookiesResult -> Bool
/= :: GetCookiesResult -> GetCookiesResult -> Bool
Eq, (forall x. GetCookiesResult -> Rep GetCookiesResult x)
-> (forall x. Rep GetCookiesResult x -> GetCookiesResult)
-> Generic GetCookiesResult
forall x. Rep GetCookiesResult x -> GetCookiesResult
forall x. GetCookiesResult -> Rep GetCookiesResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. GetCookiesResult -> Rep GetCookiesResult x
from :: forall x. GetCookiesResult -> Rep GetCookiesResult x
$cto :: forall x. Rep GetCookiesResult x -> GetCookiesResult
to :: forall x. Rep GetCookiesResult x -> GetCookiesResult
Generic)

instance FromJSON GetCookiesResult

-- | Result of setting a cookie
newtype SetCookieResult = MkSetCookieResult
  { SetCookieResult -> PartitionKey
partitionKey :: PartitionKey
  }
  deriving (Int -> SetCookieResult -> ShowS
[SetCookieResult] -> ShowS
SetCookieResult -> String
(Int -> SetCookieResult -> ShowS)
-> (SetCookieResult -> String)
-> ([SetCookieResult] -> ShowS)
-> Show SetCookieResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetCookieResult -> ShowS
showsPrec :: Int -> SetCookieResult -> ShowS
$cshow :: SetCookieResult -> String
show :: SetCookieResult -> String
$cshowList :: [SetCookieResult] -> ShowS
showList :: [SetCookieResult] -> ShowS
Show, SetCookieResult -> SetCookieResult -> Bool
(SetCookieResult -> SetCookieResult -> Bool)
-> (SetCookieResult -> SetCookieResult -> Bool)
-> Eq SetCookieResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetCookieResult -> SetCookieResult -> Bool
== :: SetCookieResult -> SetCookieResult -> Bool
$c/= :: SetCookieResult -> SetCookieResult -> Bool
/= :: SetCookieResult -> SetCookieResult -> Bool
Eq, (forall x. SetCookieResult -> Rep SetCookieResult x)
-> (forall x. Rep SetCookieResult x -> SetCookieResult)
-> Generic SetCookieResult
forall x. Rep SetCookieResult x -> SetCookieResult
forall x. SetCookieResult -> Rep SetCookieResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SetCookieResult -> Rep SetCookieResult x
from :: forall x. SetCookieResult -> Rep SetCookieResult x
$cto :: forall x. Rep SetCookieResult x -> SetCookieResult
to :: forall x. Rep SetCookieResult x -> SetCookieResult
Generic)

instance FromJSON SetCookieResult

-- | Result of deleting cookies
newtype DeleteCookiesResult = MkDeleteCookiesResult
  { DeleteCookiesResult -> PartitionKey
partitionKey :: PartitionKey
  }
  deriving (Int -> DeleteCookiesResult -> ShowS
[DeleteCookiesResult] -> ShowS
DeleteCookiesResult -> String
(Int -> DeleteCookiesResult -> ShowS)
-> (DeleteCookiesResult -> String)
-> ([DeleteCookiesResult] -> ShowS)
-> Show DeleteCookiesResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DeleteCookiesResult -> ShowS
showsPrec :: Int -> DeleteCookiesResult -> ShowS
$cshow :: DeleteCookiesResult -> String
show :: DeleteCookiesResult -> String
$cshowList :: [DeleteCookiesResult] -> ShowS
showList :: [DeleteCookiesResult] -> ShowS
Show, DeleteCookiesResult -> DeleteCookiesResult -> Bool
(DeleteCookiesResult -> DeleteCookiesResult -> Bool)
-> (DeleteCookiesResult -> DeleteCookiesResult -> Bool)
-> Eq DeleteCookiesResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DeleteCookiesResult -> DeleteCookiesResult -> Bool
== :: DeleteCookiesResult -> DeleteCookiesResult -> Bool
$c/= :: DeleteCookiesResult -> DeleteCookiesResult -> Bool
/= :: DeleteCookiesResult -> DeleteCookiesResult -> Bool
Eq, (forall x. DeleteCookiesResult -> Rep DeleteCookiesResult x)
-> (forall x. Rep DeleteCookiesResult x -> DeleteCookiesResult)
-> Generic DeleteCookiesResult
forall x. Rep DeleteCookiesResult x -> DeleteCookiesResult
forall x. DeleteCookiesResult -> Rep DeleteCookiesResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DeleteCookiesResult -> Rep DeleteCookiesResult x
from :: forall x. DeleteCookiesResult -> Rep DeleteCookiesResult x
$cto :: forall x. Rep DeleteCookiesResult x -> DeleteCookiesResult
to :: forall x. Rep DeleteCookiesResult x -> DeleteCookiesResult
Generic)

instance FromJSON DeleteCookiesResult

-- ######### Local #########

-- | Parameters for getting cookies
data GetCookies = MkGetCookies
  { GetCookies -> Maybe CookieFilter
filter :: Maybe CookieFilter,
    GetCookies -> Maybe PartitionDescriptor
partition :: Maybe PartitionDescriptor
  }
  deriving (Int -> GetCookies -> ShowS
[GetCookies] -> ShowS
GetCookies -> String
(Int -> GetCookies -> ShowS)
-> (GetCookies -> String)
-> ([GetCookies] -> ShowS)
-> Show GetCookies
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetCookies -> ShowS
showsPrec :: Int -> GetCookies -> ShowS
$cshow :: GetCookies -> String
show :: GetCookies -> String
$cshowList :: [GetCookies] -> ShowS
showList :: [GetCookies] -> ShowS
Show, GetCookies -> GetCookies -> Bool
(GetCookies -> GetCookies -> Bool)
-> (GetCookies -> GetCookies -> Bool) -> Eq GetCookies
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetCookies -> GetCookies -> Bool
== :: GetCookies -> GetCookies -> Bool
$c/= :: GetCookies -> GetCookies -> Bool
/= :: GetCookies -> GetCookies -> Bool
Eq, (forall x. GetCookies -> Rep GetCookies x)
-> (forall x. Rep GetCookies x -> GetCookies) -> Generic GetCookies
forall x. Rep GetCookies x -> GetCookies
forall x. GetCookies -> Rep GetCookies x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. GetCookies -> Rep GetCookies x
from :: forall x. GetCookies -> Rep GetCookies x
$cto :: forall x. Rep GetCookies x -> GetCookies
to :: forall x. Rep GetCookies x -> GetCookies
Generic)

instance ToJSON GetCookies where
  toJSON :: GetCookies -> Value
  toJSON :: GetCookies -> Value
toJSON = GetCookies -> Value
forall a. (Generic a, GToJSON' Value Zero (Rep a)) => a -> Value
toJSONOmitNothing

-- | Filter for cookie operations
data CookieFilter = MkCookieFilter
  { CookieFilter -> Maybe Text
name :: Maybe Text,
    CookieFilter -> Maybe BytesValue
value :: Maybe Network.BytesValue,
    CookieFilter -> Maybe Text
domain :: Maybe Text,
    CookieFilter -> Maybe Text
path :: Maybe Text,
    CookieFilter -> Maybe Int
size :: Maybe Int,
    CookieFilter -> Maybe Bool
httpOnly :: Maybe Bool,
    CookieFilter -> Maybe Bool
secure :: Maybe Bool,
    CookieFilter -> Maybe SameSite
sameSite :: Maybe Network.SameSite,
    CookieFilter -> Maybe Int
expiry :: Maybe Int
  }
  deriving (Int -> CookieFilter -> ShowS
[CookieFilter] -> ShowS
CookieFilter -> String
(Int -> CookieFilter -> ShowS)
-> (CookieFilter -> String)
-> ([CookieFilter] -> ShowS)
-> Show CookieFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CookieFilter -> ShowS
showsPrec :: Int -> CookieFilter -> ShowS
$cshow :: CookieFilter -> String
show :: CookieFilter -> String
$cshowList :: [CookieFilter] -> ShowS
showList :: [CookieFilter] -> ShowS
Show, CookieFilter -> CookieFilter -> Bool
(CookieFilter -> CookieFilter -> Bool)
-> (CookieFilter -> CookieFilter -> Bool) -> Eq CookieFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CookieFilter -> CookieFilter -> Bool
== :: CookieFilter -> CookieFilter -> Bool
$c/= :: CookieFilter -> CookieFilter -> Bool
/= :: CookieFilter -> CookieFilter -> Bool
Eq, (forall x. CookieFilter -> Rep CookieFilter x)
-> (forall x. Rep CookieFilter x -> CookieFilter)
-> Generic CookieFilter
forall x. Rep CookieFilter x -> CookieFilter
forall x. CookieFilter -> Rep CookieFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CookieFilter -> Rep CookieFilter x
from :: forall x. CookieFilter -> Rep CookieFilter x
$cto :: forall x. Rep CookieFilter x -> CookieFilter
to :: forall x. Rep CookieFilter x -> CookieFilter
Generic)

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

instance ToJSON CookieFilter where
  toJSON :: CookieFilter -> Value
  toJSON :: CookieFilter -> Value
toJSON = CookieFilter -> Value
forall a. (Generic a, GToJSON' Value Zero (Rep a)) => a -> Value
toJSONOmitNothing

-- | Descriptor for a partition
data PartitionDescriptor
  = BrowsingContextPartition
      { PartitionDescriptor -> BrowsingContext
context :: BrowsingContext
      }
  | StorageKeyPartition
      { PartitionDescriptor -> Maybe UserContext
userContext :: Maybe UserContext,
        PartitionDescriptor -> Maybe Text
sourceOrigin :: Maybe Text
      }
  deriving (Int -> PartitionDescriptor -> ShowS
[PartitionDescriptor] -> ShowS
PartitionDescriptor -> String
(Int -> PartitionDescriptor -> ShowS)
-> (PartitionDescriptor -> String)
-> ([PartitionDescriptor] -> ShowS)
-> Show PartitionDescriptor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PartitionDescriptor -> ShowS
showsPrec :: Int -> PartitionDescriptor -> ShowS
$cshow :: PartitionDescriptor -> String
show :: PartitionDescriptor -> String
$cshowList :: [PartitionDescriptor] -> ShowS
showList :: [PartitionDescriptor] -> ShowS
Show, PartitionDescriptor -> PartitionDescriptor -> Bool
(PartitionDescriptor -> PartitionDescriptor -> Bool)
-> (PartitionDescriptor -> PartitionDescriptor -> Bool)
-> Eq PartitionDescriptor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PartitionDescriptor -> PartitionDescriptor -> Bool
== :: PartitionDescriptor -> PartitionDescriptor -> Bool
$c/= :: PartitionDescriptor -> PartitionDescriptor -> Bool
/= :: PartitionDescriptor -> PartitionDescriptor -> Bool
Eq, (forall x. PartitionDescriptor -> Rep PartitionDescriptor x)
-> (forall x. Rep PartitionDescriptor x -> PartitionDescriptor)
-> Generic PartitionDescriptor
forall x. Rep PartitionDescriptor x -> PartitionDescriptor
forall x. PartitionDescriptor -> Rep PartitionDescriptor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PartitionDescriptor -> Rep PartitionDescriptor x
from :: forall x. PartitionDescriptor -> Rep PartitionDescriptor x
$cto :: forall x. Rep PartitionDescriptor x -> PartitionDescriptor
to :: forall x. Rep PartitionDescriptor x -> PartitionDescriptor
Generic)

instance FromJSON PartitionDescriptor where
  parseJSON :: Value -> Parser PartitionDescriptor
  parseJSON :: Value -> Parser PartitionDescriptor
parseJSON = String
-> (Object -> Parser PartitionDescriptor)
-> Value
-> Parser PartitionDescriptor
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"PartitionDescriptor" ((Object -> Parser PartitionDescriptor)
 -> Value -> Parser PartitionDescriptor)
-> (Object -> Parser PartitionDescriptor)
-> Value
-> Parser PartitionDescriptor
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    typ <- Object
o Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
    case typ of
      String
"context" -> BrowsingContext -> PartitionDescriptor
BrowsingContextPartition (BrowsingContext -> PartitionDescriptor)
-> Parser BrowsingContext -> Parser PartitionDescriptor
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser BrowsingContext
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"context"
      String
"storageKey" -> Maybe UserContext -> Maybe Text -> PartitionDescriptor
StorageKeyPartition (Maybe UserContext -> Maybe Text -> PartitionDescriptor)
-> Parser (Maybe UserContext)
-> Parser (Maybe Text -> PartitionDescriptor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe UserContext)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"userContext" Parser (Maybe Text -> PartitionDescriptor)
-> Parser (Maybe Text) -> Parser PartitionDescriptor
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"sourceOrigin"
      String
_ -> String -> Parser PartitionDescriptor
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser PartitionDescriptor)
-> String -> Parser PartitionDescriptor
forall a b. (a -> b) -> a -> b
$ String
"Unknown partition type: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
typ

instance ToJSON PartitionDescriptor where
  toJSON :: PartitionDescriptor -> Value
  toJSON :: PartitionDescriptor -> Value
toJSON = \case
    BrowsingContextPartition BrowsingContext
ctx ->
      [Pair] -> Value
object
        [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"context",
          Key
"context" Key -> BrowsingContext -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= BrowsingContext
ctx
        ]
    StorageKeyPartition Maybe UserContext
userCtx Maybe Text
srcOrigin ->
      [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
        [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"storageKey"
        ]
          [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes
            [ Key -> Maybe UserContext -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"userContext" Maybe UserContext
userCtx,
              Key -> Maybe Text -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"sourceOrigin" Maybe Text
srcOrigin
            ]

-- | Parameters for setting a cookie
data SetCookie = MkSetCookie
  { SetCookie -> PartialCookie
cookie :: PartialCookie,
    SetCookie -> Maybe PartitionDescriptor
partition :: Maybe PartitionDescriptor
  }
  deriving (Int -> SetCookie -> ShowS
[SetCookie] -> ShowS
SetCookie -> String
(Int -> SetCookie -> ShowS)
-> (SetCookie -> String)
-> ([SetCookie] -> ShowS)
-> Show SetCookie
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetCookie -> ShowS
showsPrec :: Int -> SetCookie -> ShowS
$cshow :: SetCookie -> String
show :: SetCookie -> String
$cshowList :: [SetCookie] -> ShowS
showList :: [SetCookie] -> ShowS
Show, SetCookie -> SetCookie -> Bool
(SetCookie -> SetCookie -> Bool)
-> (SetCookie -> SetCookie -> Bool) -> Eq SetCookie
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetCookie -> SetCookie -> Bool
== :: SetCookie -> SetCookie -> Bool
$c/= :: SetCookie -> SetCookie -> Bool
/= :: SetCookie -> SetCookie -> Bool
Eq, (forall x. SetCookie -> Rep SetCookie x)
-> (forall x. Rep SetCookie x -> SetCookie) -> Generic SetCookie
forall x. Rep SetCookie x -> SetCookie
forall x. SetCookie -> Rep SetCookie x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SetCookie -> Rep SetCookie x
from :: forall x. SetCookie -> Rep SetCookie x
$cto :: forall x. Rep SetCookie x -> SetCookie
to :: forall x. Rep SetCookie x -> SetCookie
Generic)

instance ToJSON SetCookie where
  toJSON :: SetCookie -> Value
  toJSON :: SetCookie -> Value
toJSON = SetCookie -> Value
forall a. (Generic a, GToJSON' Value Zero (Rep a)) => a -> Value
toJSONOmitNothing

-- | Partial cookie for setting
data PartialCookie = MkPartialCookie
  { PartialCookie -> Text
name :: Text,
    PartialCookie -> BytesValue
value :: Network.BytesValue,
    PartialCookie -> Text
domain :: Text,
    PartialCookie -> Maybe Text
path :: Maybe Text,
    PartialCookie -> Maybe Bool
httpOnly :: Maybe Bool,
    PartialCookie -> Maybe Bool
secure :: Maybe Bool,
    PartialCookie -> Maybe SameSite
sameSite :: Maybe Network.SameSite,
    PartialCookie -> Maybe Text
expiry :: Maybe Text
  }
  deriving (Int -> PartialCookie -> ShowS
[PartialCookie] -> ShowS
PartialCookie -> String
(Int -> PartialCookie -> ShowS)
-> (PartialCookie -> String)
-> ([PartialCookie] -> ShowS)
-> Show PartialCookie
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PartialCookie -> ShowS
showsPrec :: Int -> PartialCookie -> ShowS
$cshow :: PartialCookie -> String
show :: PartialCookie -> String
$cshowList :: [PartialCookie] -> ShowS
showList :: [PartialCookie] -> ShowS
Show, PartialCookie -> PartialCookie -> Bool
(PartialCookie -> PartialCookie -> Bool)
-> (PartialCookie -> PartialCookie -> Bool) -> Eq PartialCookie
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PartialCookie -> PartialCookie -> Bool
== :: PartialCookie -> PartialCookie -> Bool
$c/= :: PartialCookie -> PartialCookie -> Bool
/= :: PartialCookie -> PartialCookie -> Bool
Eq, (forall x. PartialCookie -> Rep PartialCookie x)
-> (forall x. Rep PartialCookie x -> PartialCookie)
-> Generic PartialCookie
forall x. Rep PartialCookie x -> PartialCookie
forall x. PartialCookie -> Rep PartialCookie x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PartialCookie -> Rep PartialCookie x
from :: forall x. PartialCookie -> Rep PartialCookie x
$cto :: forall x. Rep PartialCookie x -> PartialCookie
to :: forall x. Rep PartialCookie x -> PartialCookie
Generic)

instance ToJSON PartialCookie where
  toJSON :: PartialCookie -> Value
  toJSON :: PartialCookie -> Value
toJSON = PartialCookie -> Value
forall a. (Generic a, GToJSON' Value Zero (Rep a)) => a -> Value
toJSONOmitNothing

-- | Parameters for deleting cookies
data DeleteCookies = MkDeleteCookies
  { DeleteCookies -> Maybe CookieFilter
filter :: Maybe CookieFilter,
    DeleteCookies -> Maybe PartitionDescriptor
partition :: Maybe PartitionDescriptor
  }
  deriving (Int -> DeleteCookies -> ShowS
[DeleteCookies] -> ShowS
DeleteCookies -> String
(Int -> DeleteCookies -> ShowS)
-> (DeleteCookies -> String)
-> ([DeleteCookies] -> ShowS)
-> Show DeleteCookies
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DeleteCookies -> ShowS
showsPrec :: Int -> DeleteCookies -> ShowS
$cshow :: DeleteCookies -> String
show :: DeleteCookies -> String
$cshowList :: [DeleteCookies] -> ShowS
showList :: [DeleteCookies] -> ShowS
Show, DeleteCookies -> DeleteCookies -> Bool
(DeleteCookies -> DeleteCookies -> Bool)
-> (DeleteCookies -> DeleteCookies -> Bool) -> Eq DeleteCookies
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DeleteCookies -> DeleteCookies -> Bool
== :: DeleteCookies -> DeleteCookies -> Bool
$c/= :: DeleteCookies -> DeleteCookies -> Bool
/= :: DeleteCookies -> DeleteCookies -> Bool
Eq, (forall x. DeleteCookies -> Rep DeleteCookies x)
-> (forall x. Rep DeleteCookies x -> DeleteCookies)
-> Generic DeleteCookies
forall x. Rep DeleteCookies x -> DeleteCookies
forall x. DeleteCookies -> Rep DeleteCookies x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DeleteCookies -> Rep DeleteCookies x
from :: forall x. DeleteCookies -> Rep DeleteCookies x
$cto :: forall x. Rep DeleteCookies x -> DeleteCookies
to :: forall x. Rep DeleteCookies x -> DeleteCookies
Generic)

instance ToJSON DeleteCookies where
  toJSON :: DeleteCookies -> Value
  toJSON :: DeleteCookies -> Value
toJSON = DeleteCookies -> Value
forall a. (Generic a, GToJSON' Value Zero (Rep a)) => a -> Value
toJSONOmitNothing