{-# 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.MechanicalTurk.Types.Locale
-- 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.MechanicalTurk.Types.Locale 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

-- | The Locale data structure represents a geographical region or location.
--
-- /See:/ 'newLocale' smart constructor.
data Locale = Locale'
  { -- | The state or subdivision of the locale. A valid ISO 3166-2 subdivision
    -- code. For example, the code WA refers to the state of Washington.
    Locale -> Maybe Text
subdivision :: Prelude.Maybe Prelude.Text,
    -- | The country of the locale. Must be a valid ISO 3166 country code. For
    -- example, the code US refers to the United States of America.
    Locale -> Text
country :: Prelude.Text
  }
  deriving (Locale -> Locale -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Locale -> Locale -> Bool
$c/= :: Locale -> Locale -> Bool
== :: Locale -> Locale -> Bool
$c== :: Locale -> Locale -> Bool
Prelude.Eq, ReadPrec [Locale]
ReadPrec Locale
Int -> ReadS Locale
ReadS [Locale]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Locale]
$creadListPrec :: ReadPrec [Locale]
readPrec :: ReadPrec Locale
$creadPrec :: ReadPrec Locale
readList :: ReadS [Locale]
$creadList :: ReadS [Locale]
readsPrec :: Int -> ReadS Locale
$creadsPrec :: Int -> ReadS Locale
Prelude.Read, Int -> Locale -> ShowS
[Locale] -> ShowS
Locale -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Locale] -> ShowS
$cshowList :: [Locale] -> ShowS
show :: Locale -> String
$cshow :: Locale -> String
showsPrec :: Int -> Locale -> ShowS
$cshowsPrec :: Int -> Locale -> ShowS
Prelude.Show, forall x. Rep Locale x -> Locale
forall x. Locale -> Rep Locale x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Locale x -> Locale
$cfrom :: forall x. Locale -> Rep Locale x
Prelude.Generic)

-- |
-- Create a value of 'Locale' 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:
--
-- 'subdivision', 'locale_subdivision' - The state or subdivision of the locale. A valid ISO 3166-2 subdivision
-- code. For example, the code WA refers to the state of Washington.
--
-- 'country', 'locale_country' - The country of the locale. Must be a valid ISO 3166 country code. For
-- example, the code US refers to the United States of America.
newLocale ::
  -- | 'country'
  Prelude.Text ->
  Locale
newLocale :: Text -> Locale
newLocale Text
pCountry_ =
  Locale'
    { $sel:subdivision:Locale' :: Maybe Text
subdivision = forall a. Maybe a
Prelude.Nothing,
      $sel:country:Locale' :: Text
country = Text
pCountry_
    }

-- | The state or subdivision of the locale. A valid ISO 3166-2 subdivision
-- code. For example, the code WA refers to the state of Washington.
locale_subdivision :: Lens.Lens' Locale (Prelude.Maybe Prelude.Text)
locale_subdivision :: Lens' Locale (Maybe Text)
locale_subdivision = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Locale' {Maybe Text
subdivision :: Maybe Text
$sel:subdivision:Locale' :: Locale -> Maybe Text
subdivision} -> Maybe Text
subdivision) (\s :: Locale
s@Locale' {} Maybe Text
a -> Locale
s {$sel:subdivision:Locale' :: Maybe Text
subdivision = Maybe Text
a} :: Locale)

-- | The country of the locale. Must be a valid ISO 3166 country code. For
-- example, the code US refers to the United States of America.
locale_country :: Lens.Lens' Locale Prelude.Text
locale_country :: Lens' Locale Text
locale_country = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Locale' {Text
country :: Text
$sel:country:Locale' :: Locale -> Text
country} -> Text
country) (\s :: Locale
s@Locale' {} Text
a -> Locale
s {$sel:country:Locale' :: Text
country = Text
a} :: Locale)

instance Data.FromJSON Locale where
  parseJSON :: Value -> Parser Locale
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Locale"
      ( \Object
x ->
          Maybe Text -> Text -> Locale
Locale'
            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
"Subdivision")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Country")
      )

instance Prelude.Hashable Locale where
  hashWithSalt :: Int -> Locale -> Int
hashWithSalt Int
_salt Locale' {Maybe Text
Text
country :: Text
subdivision :: Maybe Text
$sel:country:Locale' :: Locale -> Text
$sel:subdivision:Locale' :: Locale -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
subdivision
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
country

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

instance Data.ToJSON Locale where
  toJSON :: Locale -> Value
toJSON Locale' {Maybe Text
Text
country :: Text
subdivision :: Maybe Text
$sel:country:Locale' :: Locale -> Text
$sel:subdivision:Locale' :: Locale -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Subdivision" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
subdivision,
            forall a. a -> Maybe a
Prelude.Just (Key
"Country" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
country)
          ]
      )