{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Lightsail.Types.QueryStringObject
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Lightsail.Types.QueryStringObject where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the query string parameters that an Amazon Lightsail content
-- delivery network (CDN) distribution to bases caching on.
--
-- For the query strings that you specify, your distribution caches
-- separate versions of the specified content based on the query string
-- values in viewer requests.
--
-- /See:/ 'newQueryStringObject' smart constructor.
data QueryStringObject = QueryStringObject'
  { -- | The specific query strings that the distribution forwards to the origin.
    --
    -- Your distribution will cache content based on the specified query
    -- strings.
    --
    -- If the @option@ parameter is true, then your distribution forwards all
    -- query strings, regardless of what you specify using the
    -- @queryStringsAllowList@ parameter.
    QueryStringObject -> Maybe [Text]
queryStringsAllowList :: Prelude.Maybe [Prelude.Text],
    -- | Indicates whether the distribution forwards and caches based on query
    -- strings.
    QueryStringObject -> Maybe Bool
option :: Prelude.Maybe Prelude.Bool
  }
  deriving (QueryStringObject -> QueryStringObject -> Bool
(QueryStringObject -> QueryStringObject -> Bool)
-> (QueryStringObject -> QueryStringObject -> Bool)
-> Eq QueryStringObject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryStringObject -> QueryStringObject -> Bool
$c/= :: QueryStringObject -> QueryStringObject -> Bool
== :: QueryStringObject -> QueryStringObject -> Bool
$c== :: QueryStringObject -> QueryStringObject -> Bool
Prelude.Eq, ReadPrec [QueryStringObject]
ReadPrec QueryStringObject
Int -> ReadS QueryStringObject
ReadS [QueryStringObject]
(Int -> ReadS QueryStringObject)
-> ReadS [QueryStringObject]
-> ReadPrec QueryStringObject
-> ReadPrec [QueryStringObject]
-> Read QueryStringObject
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QueryStringObject]
$creadListPrec :: ReadPrec [QueryStringObject]
readPrec :: ReadPrec QueryStringObject
$creadPrec :: ReadPrec QueryStringObject
readList :: ReadS [QueryStringObject]
$creadList :: ReadS [QueryStringObject]
readsPrec :: Int -> ReadS QueryStringObject
$creadsPrec :: Int -> ReadS QueryStringObject
Prelude.Read, Int -> QueryStringObject -> ShowS
[QueryStringObject] -> ShowS
QueryStringObject -> String
(Int -> QueryStringObject -> ShowS)
-> (QueryStringObject -> String)
-> ([QueryStringObject] -> ShowS)
-> Show QueryStringObject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryStringObject] -> ShowS
$cshowList :: [QueryStringObject] -> ShowS
show :: QueryStringObject -> String
$cshow :: QueryStringObject -> String
showsPrec :: Int -> QueryStringObject -> ShowS
$cshowsPrec :: Int -> QueryStringObject -> ShowS
Prelude.Show, (forall x. QueryStringObject -> Rep QueryStringObject x)
-> (forall x. Rep QueryStringObject x -> QueryStringObject)
-> Generic QueryStringObject
forall x. Rep QueryStringObject x -> QueryStringObject
forall x. QueryStringObject -> Rep QueryStringObject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep QueryStringObject x -> QueryStringObject
$cfrom :: forall x. QueryStringObject -> Rep QueryStringObject x
Prelude.Generic)

-- |
-- Create a value of 'QueryStringObject' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'queryStringsAllowList', 'queryStringObject_queryStringsAllowList' - The specific query strings that the distribution forwards to the origin.
--
-- Your distribution will cache content based on the specified query
-- strings.
--
-- If the @option@ parameter is true, then your distribution forwards all
-- query strings, regardless of what you specify using the
-- @queryStringsAllowList@ parameter.
--
-- 'option', 'queryStringObject_option' - Indicates whether the distribution forwards and caches based on query
-- strings.
newQueryStringObject ::
  QueryStringObject
newQueryStringObject :: QueryStringObject
newQueryStringObject =
  QueryStringObject' :: Maybe [Text] -> Maybe Bool -> QueryStringObject
QueryStringObject'
    { $sel:queryStringsAllowList:QueryStringObject' :: Maybe [Text]
queryStringsAllowList =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:option:QueryStringObject' :: Maybe Bool
option = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | The specific query strings that the distribution forwards to the origin.
--
-- Your distribution will cache content based on the specified query
-- strings.
--
-- If the @option@ parameter is true, then your distribution forwards all
-- query strings, regardless of what you specify using the
-- @queryStringsAllowList@ parameter.
queryStringObject_queryStringsAllowList :: Lens.Lens' QueryStringObject (Prelude.Maybe [Prelude.Text])
queryStringObject_queryStringsAllowList :: (Maybe [Text] -> f (Maybe [Text]))
-> QueryStringObject -> f QueryStringObject
queryStringObject_queryStringsAllowList = (QueryStringObject -> Maybe [Text])
-> (QueryStringObject -> Maybe [Text] -> QueryStringObject)
-> Lens
     QueryStringObject QueryStringObject (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryStringObject' {Maybe [Text]
queryStringsAllowList :: Maybe [Text]
$sel:queryStringsAllowList:QueryStringObject' :: QueryStringObject -> Maybe [Text]
queryStringsAllowList} -> Maybe [Text]
queryStringsAllowList) (\s :: QueryStringObject
s@QueryStringObject' {} Maybe [Text]
a -> QueryStringObject
s {$sel:queryStringsAllowList:QueryStringObject' :: Maybe [Text]
queryStringsAllowList = Maybe [Text]
a} :: QueryStringObject) ((Maybe [Text] -> f (Maybe [Text]))
 -> QueryStringObject -> f QueryStringObject)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> QueryStringObject
-> f QueryStringObject
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Indicates whether the distribution forwards and caches based on query
-- strings.
queryStringObject_option :: Lens.Lens' QueryStringObject (Prelude.Maybe Prelude.Bool)
queryStringObject_option :: (Maybe Bool -> f (Maybe Bool))
-> QueryStringObject -> f QueryStringObject
queryStringObject_option = (QueryStringObject -> Maybe Bool)
-> (QueryStringObject -> Maybe Bool -> QueryStringObject)
-> Lens
     QueryStringObject QueryStringObject (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryStringObject' {Maybe Bool
option :: Maybe Bool
$sel:option:QueryStringObject' :: QueryStringObject -> Maybe Bool
option} -> Maybe Bool
option) (\s :: QueryStringObject
s@QueryStringObject' {} Maybe Bool
a -> QueryStringObject
s {$sel:option:QueryStringObject' :: Maybe Bool
option = Maybe Bool
a} :: QueryStringObject)

instance Core.FromJSON QueryStringObject where
  parseJSON :: Value -> Parser QueryStringObject
parseJSON =
    String
-> (Object -> Parser QueryStringObject)
-> Value
-> Parser QueryStringObject
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"QueryStringObject"
      ( \Object
x ->
          Maybe [Text] -> Maybe Bool -> QueryStringObject
QueryStringObject'
            (Maybe [Text] -> Maybe Bool -> QueryStringObject)
-> Parser (Maybe [Text])
-> Parser (Maybe Bool -> QueryStringObject)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"queryStringsAllowList"
                            Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe Bool -> QueryStringObject)
-> Parser (Maybe Bool) -> Parser QueryStringObject
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"option")
      )

instance Prelude.Hashable QueryStringObject

instance Prelude.NFData QueryStringObject

instance Core.ToJSON QueryStringObject where
  toJSON :: QueryStringObject -> Value
toJSON QueryStringObject' {Maybe Bool
Maybe [Text]
option :: Maybe Bool
queryStringsAllowList :: Maybe [Text]
$sel:option:QueryStringObject' :: QueryStringObject -> Maybe Bool
$sel:queryStringsAllowList:QueryStringObject' :: QueryStringObject -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"queryStringsAllowList" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
queryStringsAllowList,
            (Text
"option" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
option
          ]
      )