{-# 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.Pinpoint.Types.SegmentLocation
-- 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.Pinpoint.Types.SegmentLocation where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.GPSPointDimension
import Amazonka.Pinpoint.Types.SetDimension
import qualified Amazonka.Prelude as Prelude

-- | Specifies geographical dimension settings for a segment.
--
-- /See:/ 'newSegmentLocation' smart constructor.
data SegmentLocation = SegmentLocation'
  { -- | The country or region code, in ISO 3166-1 alpha-2 format, for the
    -- segment.
    SegmentLocation -> Maybe SetDimension
country :: Prelude.Maybe SetDimension,
    -- | The GPS location and range for the segment.
    SegmentLocation -> Maybe GPSPointDimension
gPSPoint :: Prelude.Maybe GPSPointDimension
  }
  deriving (SegmentLocation -> SegmentLocation -> Bool
(SegmentLocation -> SegmentLocation -> Bool)
-> (SegmentLocation -> SegmentLocation -> Bool)
-> Eq SegmentLocation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SegmentLocation -> SegmentLocation -> Bool
$c/= :: SegmentLocation -> SegmentLocation -> Bool
== :: SegmentLocation -> SegmentLocation -> Bool
$c== :: SegmentLocation -> SegmentLocation -> Bool
Prelude.Eq, ReadPrec [SegmentLocation]
ReadPrec SegmentLocation
Int -> ReadS SegmentLocation
ReadS [SegmentLocation]
(Int -> ReadS SegmentLocation)
-> ReadS [SegmentLocation]
-> ReadPrec SegmentLocation
-> ReadPrec [SegmentLocation]
-> Read SegmentLocation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SegmentLocation]
$creadListPrec :: ReadPrec [SegmentLocation]
readPrec :: ReadPrec SegmentLocation
$creadPrec :: ReadPrec SegmentLocation
readList :: ReadS [SegmentLocation]
$creadList :: ReadS [SegmentLocation]
readsPrec :: Int -> ReadS SegmentLocation
$creadsPrec :: Int -> ReadS SegmentLocation
Prelude.Read, Int -> SegmentLocation -> ShowS
[SegmentLocation] -> ShowS
SegmentLocation -> String
(Int -> SegmentLocation -> ShowS)
-> (SegmentLocation -> String)
-> ([SegmentLocation] -> ShowS)
-> Show SegmentLocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SegmentLocation] -> ShowS
$cshowList :: [SegmentLocation] -> ShowS
show :: SegmentLocation -> String
$cshow :: SegmentLocation -> String
showsPrec :: Int -> SegmentLocation -> ShowS
$cshowsPrec :: Int -> SegmentLocation -> ShowS
Prelude.Show, (forall x. SegmentLocation -> Rep SegmentLocation x)
-> (forall x. Rep SegmentLocation x -> SegmentLocation)
-> Generic SegmentLocation
forall x. Rep SegmentLocation x -> SegmentLocation
forall x. SegmentLocation -> Rep SegmentLocation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SegmentLocation x -> SegmentLocation
$cfrom :: forall x. SegmentLocation -> Rep SegmentLocation x
Prelude.Generic)

-- |
-- Create a value of 'SegmentLocation' 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:
--
-- 'country', 'segmentLocation_country' - The country or region code, in ISO 3166-1 alpha-2 format, for the
-- segment.
--
-- 'gPSPoint', 'segmentLocation_gPSPoint' - The GPS location and range for the segment.
newSegmentLocation ::
  SegmentLocation
newSegmentLocation :: SegmentLocation
newSegmentLocation =
  SegmentLocation' :: Maybe SetDimension -> Maybe GPSPointDimension -> SegmentLocation
SegmentLocation'
    { $sel:country:SegmentLocation' :: Maybe SetDimension
country = Maybe SetDimension
forall a. Maybe a
Prelude.Nothing,
      $sel:gPSPoint:SegmentLocation' :: Maybe GPSPointDimension
gPSPoint = Maybe GPSPointDimension
forall a. Maybe a
Prelude.Nothing
    }

-- | The country or region code, in ISO 3166-1 alpha-2 format, for the
-- segment.
segmentLocation_country :: Lens.Lens' SegmentLocation (Prelude.Maybe SetDimension)
segmentLocation_country :: (Maybe SetDimension -> f (Maybe SetDimension))
-> SegmentLocation -> f SegmentLocation
segmentLocation_country = (SegmentLocation -> Maybe SetDimension)
-> (SegmentLocation -> Maybe SetDimension -> SegmentLocation)
-> Lens
     SegmentLocation
     SegmentLocation
     (Maybe SetDimension)
     (Maybe SetDimension)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SegmentLocation' {Maybe SetDimension
country :: Maybe SetDimension
$sel:country:SegmentLocation' :: SegmentLocation -> Maybe SetDimension
country} -> Maybe SetDimension
country) (\s :: SegmentLocation
s@SegmentLocation' {} Maybe SetDimension
a -> SegmentLocation
s {$sel:country:SegmentLocation' :: Maybe SetDimension
country = Maybe SetDimension
a} :: SegmentLocation)

-- | The GPS location and range for the segment.
segmentLocation_gPSPoint :: Lens.Lens' SegmentLocation (Prelude.Maybe GPSPointDimension)
segmentLocation_gPSPoint :: (Maybe GPSPointDimension -> f (Maybe GPSPointDimension))
-> SegmentLocation -> f SegmentLocation
segmentLocation_gPSPoint = (SegmentLocation -> Maybe GPSPointDimension)
-> (SegmentLocation -> Maybe GPSPointDimension -> SegmentLocation)
-> Lens
     SegmentLocation
     SegmentLocation
     (Maybe GPSPointDimension)
     (Maybe GPSPointDimension)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SegmentLocation' {Maybe GPSPointDimension
gPSPoint :: Maybe GPSPointDimension
$sel:gPSPoint:SegmentLocation' :: SegmentLocation -> Maybe GPSPointDimension
gPSPoint} -> Maybe GPSPointDimension
gPSPoint) (\s :: SegmentLocation
s@SegmentLocation' {} Maybe GPSPointDimension
a -> SegmentLocation
s {$sel:gPSPoint:SegmentLocation' :: Maybe GPSPointDimension
gPSPoint = Maybe GPSPointDimension
a} :: SegmentLocation)

instance Core.FromJSON SegmentLocation where
  parseJSON :: Value -> Parser SegmentLocation
parseJSON =
    String
-> (Object -> Parser SegmentLocation)
-> Value
-> Parser SegmentLocation
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SegmentLocation"
      ( \Object
x ->
          Maybe SetDimension -> Maybe GPSPointDimension -> SegmentLocation
SegmentLocation'
            (Maybe SetDimension -> Maybe GPSPointDimension -> SegmentLocation)
-> Parser (Maybe SetDimension)
-> Parser (Maybe GPSPointDimension -> SegmentLocation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe SetDimension)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Country")
            Parser (Maybe GPSPointDimension -> SegmentLocation)
-> Parser (Maybe GPSPointDimension) -> Parser SegmentLocation
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe GPSPointDimension)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"GPSPoint")
      )

instance Prelude.Hashable SegmentLocation

instance Prelude.NFData SegmentLocation

instance Core.ToJSON SegmentLocation where
  toJSON :: SegmentLocation -> Value
toJSON SegmentLocation' {Maybe GPSPointDimension
Maybe SetDimension
gPSPoint :: Maybe GPSPointDimension
country :: Maybe SetDimension
$sel:gPSPoint:SegmentLocation' :: SegmentLocation -> Maybe GPSPointDimension
$sel:country:SegmentLocation' :: SegmentLocation -> Maybe SetDimension
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Country" Text -> SetDimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SetDimension -> Pair) -> Maybe SetDimension -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SetDimension
country,
            (Text
"GPSPoint" Text -> GPSPointDimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (GPSPointDimension -> Pair)
-> Maybe GPSPointDimension -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe GPSPointDimension
gPSPoint
          ]
      )