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

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

-- | Provides information about the country that an IP address originated
-- from.
--
-- /See:/ 'newIpCountry' smart constructor.
data IpCountry = 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 -> Maybe Text
code :: Prelude.Maybe Prelude.Text,
    -- | The name of the country that the IP address originated from.
    IpCountry -> Maybe Text
name :: Prelude.Maybe Prelude.Text
  }
  deriving (IpCountry -> IpCountry -> Bool
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]
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
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. 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:
--
-- '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.
--
-- 'name', 'ipCountry_name' - The name of the country that the IP address originated from.
newIpCountry ::
  IpCountry
newIpCountry :: IpCountry
newIpCountry =
  IpCountry'
    { $sel:code:IpCountry' :: Maybe Text
code = forall a. Maybe a
Prelude.Nothing,
      $sel:name:IpCountry' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' IpCountry (Maybe Text)
ipCountry_code = 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)

-- | The name of the country that the IP address originated from.
ipCountry_name :: Lens.Lens' IpCountry (Prelude.Maybe Prelude.Text)
ipCountry_name :: Lens' IpCountry (Maybe Text)
ipCountry_name = 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)

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

instance Prelude.Hashable IpCountry where
  hashWithSalt :: Int -> IpCountry -> Int
hashWithSalt Int
_salt IpCountry' {Maybe Text
name :: Maybe Text
code :: Maybe Text
$sel:name:IpCountry' :: IpCountry -> Maybe Text
$sel:code:IpCountry' :: IpCountry -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
code
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name

instance Prelude.NFData IpCountry where
  rnf :: IpCountry -> ()
rnf IpCountry' {Maybe Text
name :: Maybe Text
code :: Maybe Text
$sel:name:IpCountry' :: IpCountry -> Maybe Text
$sel:code:IpCountry' :: IpCountry -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
code seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name