{-# 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.MacieV2.Types.IpCountry
-- 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.MacieV2.Types.IpCountry where

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

-- | Provides information about the country that an IP address originated
-- from.
--
-- /See:/ 'newIpCountry' smart constructor.
data IpCountry = IpCountry'
  { -- | The name of the country that the IP address originated from.
    IpCountry -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The two-character code, in ISO 3166-1 alpha-2 format, for the country
    -- that the IP address originated from. For example, US for the United
    -- States.
    IpCountry -> Maybe Text
code :: Prelude.Maybe Prelude.Text
  }
  deriving (IpCountry -> IpCountry -> Bool
(IpCountry -> IpCountry -> Bool)
-> (IpCountry -> IpCountry -> Bool) -> Eq IpCountry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IpCountry -> IpCountry -> Bool
$c/= :: IpCountry -> IpCountry -> Bool
== :: IpCountry -> IpCountry -> Bool
$c== :: IpCountry -> IpCountry -> Bool
Prelude.Eq, ReadPrec [IpCountry]
ReadPrec IpCountry
Int -> ReadS IpCountry
ReadS [IpCountry]
(Int -> ReadS IpCountry)
-> ReadS [IpCountry]
-> ReadPrec IpCountry
-> ReadPrec [IpCountry]
-> Read IpCountry
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IpCountry]
$creadListPrec :: ReadPrec [IpCountry]
readPrec :: ReadPrec IpCountry
$creadPrec :: ReadPrec IpCountry
readList :: ReadS [IpCountry]
$creadList :: ReadS [IpCountry]
readsPrec :: Int -> ReadS IpCountry
$creadsPrec :: Int -> ReadS IpCountry
Prelude.Read, Int -> IpCountry -> ShowS
[IpCountry] -> ShowS
IpCountry -> String
(Int -> IpCountry -> ShowS)
-> (IpCountry -> String)
-> ([IpCountry] -> ShowS)
-> Show IpCountry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IpCountry] -> ShowS
$cshowList :: [IpCountry] -> ShowS
show :: IpCountry -> String
$cshow :: IpCountry -> String
showsPrec :: Int -> IpCountry -> ShowS
$cshowsPrec :: Int -> IpCountry -> ShowS
Prelude.Show, (forall x. IpCountry -> Rep IpCountry x)
-> (forall x. Rep IpCountry x -> IpCountry) -> Generic IpCountry
forall x. Rep IpCountry x -> IpCountry
forall x. IpCountry -> Rep IpCountry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IpCountry x -> IpCountry
$cfrom :: forall x. IpCountry -> Rep IpCountry x
Prelude.Generic)

-- |
-- Create a value of 'IpCountry' 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:
--
-- 'name', 'ipCountry_name' - The name of the country that the IP address originated from.
--
-- 'code', 'ipCountry_code' - The two-character code, in ISO 3166-1 alpha-2 format, for the country
-- that the IP address originated from. For example, US for the United
-- States.
newIpCountry ::
  IpCountry
newIpCountry :: IpCountry
newIpCountry =
  IpCountry' :: Maybe Text -> Maybe Text -> IpCountry
IpCountry'
    { $sel:name:IpCountry' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:code:IpCountry' :: Maybe Text
code = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the country that the IP address originated from.
ipCountry_name :: Lens.Lens' IpCountry (Prelude.Maybe Prelude.Text)
ipCountry_name :: (Maybe Text -> f (Maybe Text)) -> IpCountry -> f IpCountry
ipCountry_name = (IpCountry -> Maybe Text)
-> (IpCountry -> Maybe Text -> IpCountry)
-> Lens IpCountry IpCountry (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IpCountry' {Maybe Text
name :: Maybe Text
$sel:name:IpCountry' :: IpCountry -> Maybe Text
name} -> Maybe Text
name) (\s :: IpCountry
s@IpCountry' {} Maybe Text
a -> IpCountry
s {$sel:name:IpCountry' :: Maybe Text
name = Maybe Text
a} :: IpCountry)

-- | The two-character code, in ISO 3166-1 alpha-2 format, for the country
-- that the IP address originated from. For example, US for the United
-- States.
ipCountry_code :: Lens.Lens' IpCountry (Prelude.Maybe Prelude.Text)
ipCountry_code :: (Maybe Text -> f (Maybe Text)) -> IpCountry -> f IpCountry
ipCountry_code = (IpCountry -> Maybe Text)
-> (IpCountry -> Maybe Text -> IpCountry)
-> Lens IpCountry IpCountry (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IpCountry' {Maybe Text
code :: Maybe Text
$sel:code:IpCountry' :: IpCountry -> Maybe Text
code} -> Maybe Text
code) (\s :: IpCountry
s@IpCountry' {} Maybe Text
a -> IpCountry
s {$sel:code:IpCountry' :: Maybe Text
code = Maybe Text
a} :: IpCountry)

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

instance Prelude.Hashable IpCountry

instance Prelude.NFData IpCountry