{-# 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.CloudDirectory.Types.FacetAttributeDefinition
-- 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.CloudDirectory.Types.FacetAttributeDefinition where

import Amazonka.CloudDirectory.Types.FacetAttributeType
import Amazonka.CloudDirectory.Types.Rule
import Amazonka.CloudDirectory.Types.TypedAttributeValue
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 facet attribute definition. See
-- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/schemas_attributereferences.html Attribute References>
-- for more information.
--
-- /See:/ 'newFacetAttributeDefinition' smart constructor.
data FacetAttributeDefinition = FacetAttributeDefinition'
  { -- | The default value of the attribute (if configured).
    FacetAttributeDefinition -> Maybe TypedAttributeValue
defaultValue :: Prelude.Maybe TypedAttributeValue,
    -- | Whether the attribute is mutable or not.
    FacetAttributeDefinition -> Maybe Bool
isImmutable :: Prelude.Maybe Prelude.Bool,
    -- | Validation rules attached to the attribute definition.
    FacetAttributeDefinition -> Maybe (HashMap Text Rule)
rules :: Prelude.Maybe (Prelude.HashMap Prelude.Text Rule),
    -- | The type of the attribute.
    FacetAttributeDefinition -> FacetAttributeType
type' :: FacetAttributeType
  }
  deriving (FacetAttributeDefinition -> FacetAttributeDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FacetAttributeDefinition -> FacetAttributeDefinition -> Bool
$c/= :: FacetAttributeDefinition -> FacetAttributeDefinition -> Bool
== :: FacetAttributeDefinition -> FacetAttributeDefinition -> Bool
$c== :: FacetAttributeDefinition -> FacetAttributeDefinition -> Bool
Prelude.Eq, ReadPrec [FacetAttributeDefinition]
ReadPrec FacetAttributeDefinition
Int -> ReadS FacetAttributeDefinition
ReadS [FacetAttributeDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FacetAttributeDefinition]
$creadListPrec :: ReadPrec [FacetAttributeDefinition]
readPrec :: ReadPrec FacetAttributeDefinition
$creadPrec :: ReadPrec FacetAttributeDefinition
readList :: ReadS [FacetAttributeDefinition]
$creadList :: ReadS [FacetAttributeDefinition]
readsPrec :: Int -> ReadS FacetAttributeDefinition
$creadsPrec :: Int -> ReadS FacetAttributeDefinition
Prelude.Read, Int -> FacetAttributeDefinition -> ShowS
[FacetAttributeDefinition] -> ShowS
FacetAttributeDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FacetAttributeDefinition] -> ShowS
$cshowList :: [FacetAttributeDefinition] -> ShowS
show :: FacetAttributeDefinition -> String
$cshow :: FacetAttributeDefinition -> String
showsPrec :: Int -> FacetAttributeDefinition -> ShowS
$cshowsPrec :: Int -> FacetAttributeDefinition -> ShowS
Prelude.Show, forall x.
Rep FacetAttributeDefinition x -> FacetAttributeDefinition
forall x.
FacetAttributeDefinition -> Rep FacetAttributeDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep FacetAttributeDefinition x -> FacetAttributeDefinition
$cfrom :: forall x.
FacetAttributeDefinition -> Rep FacetAttributeDefinition x
Prelude.Generic)

-- |
-- Create a value of 'FacetAttributeDefinition' 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:
--
-- 'defaultValue', 'facetAttributeDefinition_defaultValue' - The default value of the attribute (if configured).
--
-- 'isImmutable', 'facetAttributeDefinition_isImmutable' - Whether the attribute is mutable or not.
--
-- 'rules', 'facetAttributeDefinition_rules' - Validation rules attached to the attribute definition.
--
-- 'type'', 'facetAttributeDefinition_type' - The type of the attribute.
newFacetAttributeDefinition ::
  -- | 'type''
  FacetAttributeType ->
  FacetAttributeDefinition
newFacetAttributeDefinition :: FacetAttributeType -> FacetAttributeDefinition
newFacetAttributeDefinition FacetAttributeType
pType_ =
  FacetAttributeDefinition'
    { $sel:defaultValue:FacetAttributeDefinition' :: Maybe TypedAttributeValue
defaultValue =
        forall a. Maybe a
Prelude.Nothing,
      $sel:isImmutable:FacetAttributeDefinition' :: Maybe Bool
isImmutable = forall a. Maybe a
Prelude.Nothing,
      $sel:rules:FacetAttributeDefinition' :: Maybe (HashMap Text Rule)
rules = forall a. Maybe a
Prelude.Nothing,
      $sel:type':FacetAttributeDefinition' :: FacetAttributeType
type' = FacetAttributeType
pType_
    }

-- | The default value of the attribute (if configured).
facetAttributeDefinition_defaultValue :: Lens.Lens' FacetAttributeDefinition (Prelude.Maybe TypedAttributeValue)
facetAttributeDefinition_defaultValue :: Lens' FacetAttributeDefinition (Maybe TypedAttributeValue)
facetAttributeDefinition_defaultValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetAttributeDefinition' {Maybe TypedAttributeValue
defaultValue :: Maybe TypedAttributeValue
$sel:defaultValue:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe TypedAttributeValue
defaultValue} -> Maybe TypedAttributeValue
defaultValue) (\s :: FacetAttributeDefinition
s@FacetAttributeDefinition' {} Maybe TypedAttributeValue
a -> FacetAttributeDefinition
s {$sel:defaultValue:FacetAttributeDefinition' :: Maybe TypedAttributeValue
defaultValue = Maybe TypedAttributeValue
a} :: FacetAttributeDefinition)

-- | Whether the attribute is mutable or not.
facetAttributeDefinition_isImmutable :: Lens.Lens' FacetAttributeDefinition (Prelude.Maybe Prelude.Bool)
facetAttributeDefinition_isImmutable :: Lens' FacetAttributeDefinition (Maybe Bool)
facetAttributeDefinition_isImmutable = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetAttributeDefinition' {Maybe Bool
isImmutable :: Maybe Bool
$sel:isImmutable:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe Bool
isImmutable} -> Maybe Bool
isImmutable) (\s :: FacetAttributeDefinition
s@FacetAttributeDefinition' {} Maybe Bool
a -> FacetAttributeDefinition
s {$sel:isImmutable:FacetAttributeDefinition' :: Maybe Bool
isImmutable = Maybe Bool
a} :: FacetAttributeDefinition)

-- | Validation rules attached to the attribute definition.
facetAttributeDefinition_rules :: Lens.Lens' FacetAttributeDefinition (Prelude.Maybe (Prelude.HashMap Prelude.Text Rule))
facetAttributeDefinition_rules :: Lens' FacetAttributeDefinition (Maybe (HashMap Text Rule))
facetAttributeDefinition_rules = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetAttributeDefinition' {Maybe (HashMap Text Rule)
rules :: Maybe (HashMap Text Rule)
$sel:rules:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe (HashMap Text Rule)
rules} -> Maybe (HashMap Text Rule)
rules) (\s :: FacetAttributeDefinition
s@FacetAttributeDefinition' {} Maybe (HashMap Text Rule)
a -> FacetAttributeDefinition
s {$sel:rules:FacetAttributeDefinition' :: Maybe (HashMap Text Rule)
rules = Maybe (HashMap Text Rule)
a} :: FacetAttributeDefinition) 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 type of the attribute.
facetAttributeDefinition_type :: Lens.Lens' FacetAttributeDefinition FacetAttributeType
facetAttributeDefinition_type :: Lens' FacetAttributeDefinition FacetAttributeType
facetAttributeDefinition_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetAttributeDefinition' {FacetAttributeType
type' :: FacetAttributeType
$sel:type':FacetAttributeDefinition' :: FacetAttributeDefinition -> FacetAttributeType
type'} -> FacetAttributeType
type') (\s :: FacetAttributeDefinition
s@FacetAttributeDefinition' {} FacetAttributeType
a -> FacetAttributeDefinition
s {$sel:type':FacetAttributeDefinition' :: FacetAttributeType
type' = FacetAttributeType
a} :: FacetAttributeDefinition)

instance Data.FromJSON FacetAttributeDefinition where
  parseJSON :: Value -> Parser FacetAttributeDefinition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FacetAttributeDefinition"
      ( \Object
x ->
          Maybe TypedAttributeValue
-> Maybe Bool
-> Maybe (HashMap Text Rule)
-> FacetAttributeType
-> FacetAttributeDefinition
FacetAttributeDefinition'
            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
"DefaultValue")
            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
"IsImmutable")
            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
"Rules" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"Type")
      )

instance Prelude.Hashable FacetAttributeDefinition where
  hashWithSalt :: Int -> FacetAttributeDefinition -> Int
hashWithSalt Int
_salt FacetAttributeDefinition' {Maybe Bool
Maybe (HashMap Text Rule)
Maybe TypedAttributeValue
FacetAttributeType
type' :: FacetAttributeType
rules :: Maybe (HashMap Text Rule)
isImmutable :: Maybe Bool
defaultValue :: Maybe TypedAttributeValue
$sel:type':FacetAttributeDefinition' :: FacetAttributeDefinition -> FacetAttributeType
$sel:rules:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe (HashMap Text Rule)
$sel:isImmutable:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe Bool
$sel:defaultValue:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe TypedAttributeValue
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe TypedAttributeValue
defaultValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
isImmutable
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Rule)
rules
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FacetAttributeType
type'

instance Prelude.NFData FacetAttributeDefinition where
  rnf :: FacetAttributeDefinition -> ()
rnf FacetAttributeDefinition' {Maybe Bool
Maybe (HashMap Text Rule)
Maybe TypedAttributeValue
FacetAttributeType
type' :: FacetAttributeType
rules :: Maybe (HashMap Text Rule)
isImmutable :: Maybe Bool
defaultValue :: Maybe TypedAttributeValue
$sel:type':FacetAttributeDefinition' :: FacetAttributeDefinition -> FacetAttributeType
$sel:rules:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe (HashMap Text Rule)
$sel:isImmutable:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe Bool
$sel:defaultValue:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe TypedAttributeValue
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe TypedAttributeValue
defaultValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
isImmutable
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Rule)
rules
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf FacetAttributeType
type'

instance Data.ToJSON FacetAttributeDefinition where
  toJSON :: FacetAttributeDefinition -> Value
toJSON FacetAttributeDefinition' {Maybe Bool
Maybe (HashMap Text Rule)
Maybe TypedAttributeValue
FacetAttributeType
type' :: FacetAttributeType
rules :: Maybe (HashMap Text Rule)
isImmutable :: Maybe Bool
defaultValue :: Maybe TypedAttributeValue
$sel:type':FacetAttributeDefinition' :: FacetAttributeDefinition -> FacetAttributeType
$sel:rules:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe (HashMap Text Rule)
$sel:isImmutable:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe Bool
$sel:defaultValue:FacetAttributeDefinition' :: FacetAttributeDefinition -> Maybe TypedAttributeValue
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DefaultValue" 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 TypedAttributeValue
defaultValue,
            (Key
"IsImmutable" 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 Bool
isImmutable,
            (Key
"Rules" 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 (HashMap Text Rule)
rules,
            forall a. a -> Maybe a
Prelude.Just (Key
"Type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FacetAttributeType
type')
          ]
      )