{-# 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.CloudFront.Types.GeoRestriction
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudFront.Types.GeoRestriction where

import Amazonka.CloudFront.Types.GeoRestrictionType
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | A complex type that controls the countries in which your content is
-- distributed. CloudFront determines the location of your users using
-- @MaxMind@ GeoIP databases.
--
-- /See:/ 'newGeoRestriction' smart constructor.
data GeoRestriction = GeoRestriction'
  { -- | A complex type that contains a @Location@ element for each country in
    -- which you want CloudFront either to distribute your content
    -- (@whitelist@) or not distribute your content (@blacklist@).
    --
    -- The @Location@ element is a two-letter, uppercase country code for a
    -- country that you want to include in your @blacklist@ or @whitelist@.
    -- Include one @Location@ element for each country.
    --
    -- CloudFront and @MaxMind@ both use @ISO 3166@ country codes. For the
    -- current list of countries and the corresponding codes, see
    -- @ISO 3166-1-alpha-2@ code on the /International Organization for
    -- Standardization/ website. You can also refer to the country list on the
    -- CloudFront console, which includes both country names and codes.
    GeoRestriction -> Maybe [Text]
items :: Prelude.Maybe [Prelude.Text],
    -- | The method that you want to use to restrict distribution of your content
    -- by country:
    --
    -- -   @none@: No geo restriction is enabled, meaning access to content is
    --     not restricted by client geo location.
    --
    -- -   @blacklist@: The @Location@ elements specify the countries in which
    --     you don\'t want CloudFront to distribute your content.
    --
    -- -   @whitelist@: The @Location@ elements specify the countries in which
    --     you want CloudFront to distribute your content.
    GeoRestriction -> GeoRestrictionType
restrictionType :: GeoRestrictionType,
    -- | When geo restriction is @enabled@, this is the number of countries in
    -- your @whitelist@ or @blacklist@. Otherwise, when it is not enabled,
    -- @Quantity@ is @0@, and you can omit @Items@.
    GeoRestriction -> Int
quantity :: Prelude.Int
  }
  deriving (GeoRestriction -> GeoRestriction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GeoRestriction -> GeoRestriction -> Bool
$c/= :: GeoRestriction -> GeoRestriction -> Bool
== :: GeoRestriction -> GeoRestriction -> Bool
$c== :: GeoRestriction -> GeoRestriction -> Bool
Prelude.Eq, ReadPrec [GeoRestriction]
ReadPrec GeoRestriction
Int -> ReadS GeoRestriction
ReadS [GeoRestriction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GeoRestriction]
$creadListPrec :: ReadPrec [GeoRestriction]
readPrec :: ReadPrec GeoRestriction
$creadPrec :: ReadPrec GeoRestriction
readList :: ReadS [GeoRestriction]
$creadList :: ReadS [GeoRestriction]
readsPrec :: Int -> ReadS GeoRestriction
$creadsPrec :: Int -> ReadS GeoRestriction
Prelude.Read, Int -> GeoRestriction -> ShowS
[GeoRestriction] -> ShowS
GeoRestriction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GeoRestriction] -> ShowS
$cshowList :: [GeoRestriction] -> ShowS
show :: GeoRestriction -> String
$cshow :: GeoRestriction -> String
showsPrec :: Int -> GeoRestriction -> ShowS
$cshowsPrec :: Int -> GeoRestriction -> ShowS
Prelude.Show, forall x. Rep GeoRestriction x -> GeoRestriction
forall x. GeoRestriction -> Rep GeoRestriction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GeoRestriction x -> GeoRestriction
$cfrom :: forall x. GeoRestriction -> Rep GeoRestriction x
Prelude.Generic)

-- |
-- Create a value of 'GeoRestriction' 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:
--
-- 'items', 'geoRestriction_items' - A complex type that contains a @Location@ element for each country in
-- which you want CloudFront either to distribute your content
-- (@whitelist@) or not distribute your content (@blacklist@).
--
-- The @Location@ element is a two-letter, uppercase country code for a
-- country that you want to include in your @blacklist@ or @whitelist@.
-- Include one @Location@ element for each country.
--
-- CloudFront and @MaxMind@ both use @ISO 3166@ country codes. For the
-- current list of countries and the corresponding codes, see
-- @ISO 3166-1-alpha-2@ code on the /International Organization for
-- Standardization/ website. You can also refer to the country list on the
-- CloudFront console, which includes both country names and codes.
--
-- 'restrictionType', 'geoRestriction_restrictionType' - The method that you want to use to restrict distribution of your content
-- by country:
--
-- -   @none@: No geo restriction is enabled, meaning access to content is
--     not restricted by client geo location.
--
-- -   @blacklist@: The @Location@ elements specify the countries in which
--     you don\'t want CloudFront to distribute your content.
--
-- -   @whitelist@: The @Location@ elements specify the countries in which
--     you want CloudFront to distribute your content.
--
-- 'quantity', 'geoRestriction_quantity' - When geo restriction is @enabled@, this is the number of countries in
-- your @whitelist@ or @blacklist@. Otherwise, when it is not enabled,
-- @Quantity@ is @0@, and you can omit @Items@.
newGeoRestriction ::
  -- | 'restrictionType'
  GeoRestrictionType ->
  -- | 'quantity'
  Prelude.Int ->
  GeoRestriction
newGeoRestriction :: GeoRestrictionType -> Int -> GeoRestriction
newGeoRestriction GeoRestrictionType
pRestrictionType_ Int
pQuantity_ =
  GeoRestriction'
    { $sel:items:GeoRestriction' :: Maybe [Text]
items = forall a. Maybe a
Prelude.Nothing,
      $sel:restrictionType:GeoRestriction' :: GeoRestrictionType
restrictionType = GeoRestrictionType
pRestrictionType_,
      $sel:quantity:GeoRestriction' :: Int
quantity = Int
pQuantity_
    }

-- | A complex type that contains a @Location@ element for each country in
-- which you want CloudFront either to distribute your content
-- (@whitelist@) or not distribute your content (@blacklist@).
--
-- The @Location@ element is a two-letter, uppercase country code for a
-- country that you want to include in your @blacklist@ or @whitelist@.
-- Include one @Location@ element for each country.
--
-- CloudFront and @MaxMind@ both use @ISO 3166@ country codes. For the
-- current list of countries and the corresponding codes, see
-- @ISO 3166-1-alpha-2@ code on the /International Organization for
-- Standardization/ website. You can also refer to the country list on the
-- CloudFront console, which includes both country names and codes.
geoRestriction_items :: Lens.Lens' GeoRestriction (Prelude.Maybe [Prelude.Text])
geoRestriction_items :: Lens' GeoRestriction (Maybe [Text])
geoRestriction_items = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GeoRestriction' {Maybe [Text]
items :: Maybe [Text]
$sel:items:GeoRestriction' :: GeoRestriction -> Maybe [Text]
items} -> Maybe [Text]
items) (\s :: GeoRestriction
s@GeoRestriction' {} Maybe [Text]
a -> GeoRestriction
s {$sel:items:GeoRestriction' :: Maybe [Text]
items = Maybe [Text]
a} :: GeoRestriction) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The method that you want to use to restrict distribution of your content
-- by country:
--
-- -   @none@: No geo restriction is enabled, meaning access to content is
--     not restricted by client geo location.
--
-- -   @blacklist@: The @Location@ elements specify the countries in which
--     you don\'t want CloudFront to distribute your content.
--
-- -   @whitelist@: The @Location@ elements specify the countries in which
--     you want CloudFront to distribute your content.
geoRestriction_restrictionType :: Lens.Lens' GeoRestriction GeoRestrictionType
geoRestriction_restrictionType :: Lens' GeoRestriction GeoRestrictionType
geoRestriction_restrictionType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GeoRestriction' {GeoRestrictionType
restrictionType :: GeoRestrictionType
$sel:restrictionType:GeoRestriction' :: GeoRestriction -> GeoRestrictionType
restrictionType} -> GeoRestrictionType
restrictionType) (\s :: GeoRestriction
s@GeoRestriction' {} GeoRestrictionType
a -> GeoRestriction
s {$sel:restrictionType:GeoRestriction' :: GeoRestrictionType
restrictionType = GeoRestrictionType
a} :: GeoRestriction)

-- | When geo restriction is @enabled@, this is the number of countries in
-- your @whitelist@ or @blacklist@. Otherwise, when it is not enabled,
-- @Quantity@ is @0@, and you can omit @Items@.
geoRestriction_quantity :: Lens.Lens' GeoRestriction Prelude.Int
geoRestriction_quantity :: Lens' GeoRestriction Int
geoRestriction_quantity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GeoRestriction' {Int
quantity :: Int
$sel:quantity:GeoRestriction' :: GeoRestriction -> Int
quantity} -> Int
quantity) (\s :: GeoRestriction
s@GeoRestriction' {} Int
a -> GeoRestriction
s {$sel:quantity:GeoRestriction' :: Int
quantity = Int
a} :: GeoRestriction)

instance Data.FromXML GeoRestriction where
  parseXML :: [Node] -> Either String GeoRestriction
parseXML [Node]
x =
    Maybe [Text] -> GeoRestrictionType -> Int -> GeoRestriction
GeoRestriction'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Items"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"Location")
                  )
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"RestrictionType")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Quantity")

instance Prelude.Hashable GeoRestriction where
  hashWithSalt :: Int -> GeoRestriction -> Int
hashWithSalt Int
_salt GeoRestriction' {Int
Maybe [Text]
GeoRestrictionType
quantity :: Int
restrictionType :: GeoRestrictionType
items :: Maybe [Text]
$sel:quantity:GeoRestriction' :: GeoRestriction -> Int
$sel:restrictionType:GeoRestriction' :: GeoRestriction -> GeoRestrictionType
$sel:items:GeoRestriction' :: GeoRestriction -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
items
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` GeoRestrictionType
restrictionType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
quantity

instance Prelude.NFData GeoRestriction where
  rnf :: GeoRestriction -> ()
rnf GeoRestriction' {Int
Maybe [Text]
GeoRestrictionType
quantity :: Int
restrictionType :: GeoRestrictionType
items :: Maybe [Text]
$sel:quantity:GeoRestriction' :: GeoRestriction -> Int
$sel:restrictionType:GeoRestriction' :: GeoRestriction -> GeoRestrictionType
$sel:items:GeoRestriction' :: GeoRestriction -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
items
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf GeoRestrictionType
restrictionType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
quantity

instance Data.ToXML GeoRestriction where
  toXML :: GeoRestriction -> XML
toXML GeoRestriction' {Int
Maybe [Text]
GeoRestrictionType
quantity :: Int
restrictionType :: GeoRestrictionType
items :: Maybe [Text]
$sel:quantity:GeoRestriction' :: GeoRestriction -> Int
$sel:restrictionType:GeoRestriction' :: GeoRestriction -> GeoRestrictionType
$sel:items:GeoRestriction' :: GeoRestriction -> Maybe [Text]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Items"
          forall a. ToXML a => Name -> a -> XML
Data.@= forall a. ToXML a => a -> XML
Data.toXML
            (forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"Location" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
items),
        Name
"RestrictionType" forall a. ToXML a => Name -> a -> XML
Data.@= GeoRestrictionType
restrictionType,
        Name
"Quantity" forall a. ToXML a => Name -> a -> XML
Data.@= Int
quantity
      ]