{-# 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.FacetAttribute
-- 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.FacetAttribute where

import Amazonka.CloudDirectory.Types.FacetAttributeDefinition
import Amazonka.CloudDirectory.Types.FacetAttributeReference
import Amazonka.CloudDirectory.Types.RequiredAttributeBehavior
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

-- | An attribute that is associated with the Facet.
--
-- /See:/ 'newFacetAttribute' smart constructor.
data FacetAttribute = FacetAttribute'
  { -- | A facet attribute consists of either a definition or a reference. This
    -- structure contains the attribute definition. See
    -- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/schemas_attributereferences.html Attribute References>
    -- for more information.
    FacetAttribute -> Maybe FacetAttributeDefinition
attributeDefinition :: Prelude.Maybe FacetAttributeDefinition,
    -- | An attribute reference that is associated with the attribute. See
    -- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/schemas_attributereferences.html Attribute References>
    -- for more information.
    FacetAttribute -> Maybe FacetAttributeReference
attributeReference :: Prelude.Maybe FacetAttributeReference,
    -- | The required behavior of the @FacetAttribute@.
    FacetAttribute -> Maybe RequiredAttributeBehavior
requiredBehavior :: Prelude.Maybe RequiredAttributeBehavior,
    -- | The name of the facet attribute.
    FacetAttribute -> Text
name :: Prelude.Text
  }
  deriving (FacetAttribute -> FacetAttribute -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FacetAttribute -> FacetAttribute -> Bool
$c/= :: FacetAttribute -> FacetAttribute -> Bool
== :: FacetAttribute -> FacetAttribute -> Bool
$c== :: FacetAttribute -> FacetAttribute -> Bool
Prelude.Eq, ReadPrec [FacetAttribute]
ReadPrec FacetAttribute
Int -> ReadS FacetAttribute
ReadS [FacetAttribute]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FacetAttribute]
$creadListPrec :: ReadPrec [FacetAttribute]
readPrec :: ReadPrec FacetAttribute
$creadPrec :: ReadPrec FacetAttribute
readList :: ReadS [FacetAttribute]
$creadList :: ReadS [FacetAttribute]
readsPrec :: Int -> ReadS FacetAttribute
$creadsPrec :: Int -> ReadS FacetAttribute
Prelude.Read, Int -> FacetAttribute -> ShowS
[FacetAttribute] -> ShowS
FacetAttribute -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FacetAttribute] -> ShowS
$cshowList :: [FacetAttribute] -> ShowS
show :: FacetAttribute -> String
$cshow :: FacetAttribute -> String
showsPrec :: Int -> FacetAttribute -> ShowS
$cshowsPrec :: Int -> FacetAttribute -> ShowS
Prelude.Show, forall x. Rep FacetAttribute x -> FacetAttribute
forall x. FacetAttribute -> Rep FacetAttribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FacetAttribute x -> FacetAttribute
$cfrom :: forall x. FacetAttribute -> Rep FacetAttribute x
Prelude.Generic)

-- |
-- Create a value of 'FacetAttribute' 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:
--
-- 'attributeDefinition', 'facetAttribute_attributeDefinition' - A facet attribute consists of either a definition or a reference. This
-- structure contains the attribute definition. See
-- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/schemas_attributereferences.html Attribute References>
-- for more information.
--
-- 'attributeReference', 'facetAttribute_attributeReference' - An attribute reference that is associated with the attribute. See
-- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/schemas_attributereferences.html Attribute References>
-- for more information.
--
-- 'requiredBehavior', 'facetAttribute_requiredBehavior' - The required behavior of the @FacetAttribute@.
--
-- 'name', 'facetAttribute_name' - The name of the facet attribute.
newFacetAttribute ::
  -- | 'name'
  Prelude.Text ->
  FacetAttribute
newFacetAttribute :: Text -> FacetAttribute
newFacetAttribute Text
pName_ =
  FacetAttribute'
    { $sel:attributeDefinition:FacetAttribute' :: Maybe FacetAttributeDefinition
attributeDefinition =
        forall a. Maybe a
Prelude.Nothing,
      $sel:attributeReference:FacetAttribute' :: Maybe FacetAttributeReference
attributeReference = forall a. Maybe a
Prelude.Nothing,
      $sel:requiredBehavior:FacetAttribute' :: Maybe RequiredAttributeBehavior
requiredBehavior = forall a. Maybe a
Prelude.Nothing,
      $sel:name:FacetAttribute' :: Text
name = Text
pName_
    }

-- | A facet attribute consists of either a definition or a reference. This
-- structure contains the attribute definition. See
-- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/schemas_attributereferences.html Attribute References>
-- for more information.
facetAttribute_attributeDefinition :: Lens.Lens' FacetAttribute (Prelude.Maybe FacetAttributeDefinition)
facetAttribute_attributeDefinition :: Lens' FacetAttribute (Maybe FacetAttributeDefinition)
facetAttribute_attributeDefinition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetAttribute' {Maybe FacetAttributeDefinition
attributeDefinition :: Maybe FacetAttributeDefinition
$sel:attributeDefinition:FacetAttribute' :: FacetAttribute -> Maybe FacetAttributeDefinition
attributeDefinition} -> Maybe FacetAttributeDefinition
attributeDefinition) (\s :: FacetAttribute
s@FacetAttribute' {} Maybe FacetAttributeDefinition
a -> FacetAttribute
s {$sel:attributeDefinition:FacetAttribute' :: Maybe FacetAttributeDefinition
attributeDefinition = Maybe FacetAttributeDefinition
a} :: FacetAttribute)

-- | An attribute reference that is associated with the attribute. See
-- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/schemas_attributereferences.html Attribute References>
-- for more information.
facetAttribute_attributeReference :: Lens.Lens' FacetAttribute (Prelude.Maybe FacetAttributeReference)
facetAttribute_attributeReference :: Lens' FacetAttribute (Maybe FacetAttributeReference)
facetAttribute_attributeReference = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetAttribute' {Maybe FacetAttributeReference
attributeReference :: Maybe FacetAttributeReference
$sel:attributeReference:FacetAttribute' :: FacetAttribute -> Maybe FacetAttributeReference
attributeReference} -> Maybe FacetAttributeReference
attributeReference) (\s :: FacetAttribute
s@FacetAttribute' {} Maybe FacetAttributeReference
a -> FacetAttribute
s {$sel:attributeReference:FacetAttribute' :: Maybe FacetAttributeReference
attributeReference = Maybe FacetAttributeReference
a} :: FacetAttribute)

-- | The required behavior of the @FacetAttribute@.
facetAttribute_requiredBehavior :: Lens.Lens' FacetAttribute (Prelude.Maybe RequiredAttributeBehavior)
facetAttribute_requiredBehavior :: Lens' FacetAttribute (Maybe RequiredAttributeBehavior)
facetAttribute_requiredBehavior = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetAttribute' {Maybe RequiredAttributeBehavior
requiredBehavior :: Maybe RequiredAttributeBehavior
$sel:requiredBehavior:FacetAttribute' :: FacetAttribute -> Maybe RequiredAttributeBehavior
requiredBehavior} -> Maybe RequiredAttributeBehavior
requiredBehavior) (\s :: FacetAttribute
s@FacetAttribute' {} Maybe RequiredAttributeBehavior
a -> FacetAttribute
s {$sel:requiredBehavior:FacetAttribute' :: Maybe RequiredAttributeBehavior
requiredBehavior = Maybe RequiredAttributeBehavior
a} :: FacetAttribute)

-- | The name of the facet attribute.
facetAttribute_name :: Lens.Lens' FacetAttribute Prelude.Text
facetAttribute_name :: Lens' FacetAttribute Text
facetAttribute_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetAttribute' {Text
name :: Text
$sel:name:FacetAttribute' :: FacetAttribute -> Text
name} -> Text
name) (\s :: FacetAttribute
s@FacetAttribute' {} Text
a -> FacetAttribute
s {$sel:name:FacetAttribute' :: Text
name = Text
a} :: FacetAttribute)

instance Data.FromJSON FacetAttribute where
  parseJSON :: Value -> Parser FacetAttribute
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FacetAttribute"
      ( \Object
x ->
          Maybe FacetAttributeDefinition
-> Maybe FacetAttributeReference
-> Maybe RequiredAttributeBehavior
-> Text
-> FacetAttribute
FacetAttribute'
            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
"AttributeDefinition")
            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
"AttributeReference")
            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
"RequiredBehavior")
            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
"Name")
      )

instance Prelude.Hashable FacetAttribute where
  hashWithSalt :: Int -> FacetAttribute -> Int
hashWithSalt Int
_salt FacetAttribute' {Maybe FacetAttributeReference
Maybe RequiredAttributeBehavior
Maybe FacetAttributeDefinition
Text
name :: Text
requiredBehavior :: Maybe RequiredAttributeBehavior
attributeReference :: Maybe FacetAttributeReference
attributeDefinition :: Maybe FacetAttributeDefinition
$sel:name:FacetAttribute' :: FacetAttribute -> Text
$sel:requiredBehavior:FacetAttribute' :: FacetAttribute -> Maybe RequiredAttributeBehavior
$sel:attributeReference:FacetAttribute' :: FacetAttribute -> Maybe FacetAttributeReference
$sel:attributeDefinition:FacetAttribute' :: FacetAttribute -> Maybe FacetAttributeDefinition
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe FacetAttributeDefinition
attributeDefinition
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe FacetAttributeReference
attributeReference
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RequiredAttributeBehavior
requiredBehavior
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData FacetAttribute where
  rnf :: FacetAttribute -> ()
rnf FacetAttribute' {Maybe FacetAttributeReference
Maybe RequiredAttributeBehavior
Maybe FacetAttributeDefinition
Text
name :: Text
requiredBehavior :: Maybe RequiredAttributeBehavior
attributeReference :: Maybe FacetAttributeReference
attributeDefinition :: Maybe FacetAttributeDefinition
$sel:name:FacetAttribute' :: FacetAttribute -> Text
$sel:requiredBehavior:FacetAttribute' :: FacetAttribute -> Maybe RequiredAttributeBehavior
$sel:attributeReference:FacetAttribute' :: FacetAttribute -> Maybe FacetAttributeReference
$sel:attributeDefinition:FacetAttribute' :: FacetAttribute -> Maybe FacetAttributeDefinition
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe FacetAttributeDefinition
attributeDefinition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe FacetAttributeReference
attributeReference
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe RequiredAttributeBehavior
requiredBehavior
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name

instance Data.ToJSON FacetAttribute where
  toJSON :: FacetAttribute -> Value
toJSON FacetAttribute' {Maybe FacetAttributeReference
Maybe RequiredAttributeBehavior
Maybe FacetAttributeDefinition
Text
name :: Text
requiredBehavior :: Maybe RequiredAttributeBehavior
attributeReference :: Maybe FacetAttributeReference
attributeDefinition :: Maybe FacetAttributeDefinition
$sel:name:FacetAttribute' :: FacetAttribute -> Text
$sel:requiredBehavior:FacetAttribute' :: FacetAttribute -> Maybe RequiredAttributeBehavior
$sel:attributeReference:FacetAttribute' :: FacetAttribute -> Maybe FacetAttributeReference
$sel:attributeDefinition:FacetAttribute' :: FacetAttribute -> Maybe FacetAttributeDefinition
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AttributeDefinition" 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 FacetAttributeDefinition
attributeDefinition,
            (Key
"AttributeReference" 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 FacetAttributeReference
attributeReference,
            (Key
"RequiredBehavior" 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 RequiredAttributeBehavior
requiredBehavior,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name)
          ]
      )