{-# 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-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.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.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An attribute that is associated with the Facet.
--
-- /See:/ 'newFacetAttribute' smart constructor.
data FacetAttribute = 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 -> Maybe FacetAttributeReference
attributeReference :: Prelude.Maybe FacetAttributeReference,
    -- | 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,
    -- | 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
(FacetAttribute -> FacetAttribute -> Bool)
-> (FacetAttribute -> FacetAttribute -> Bool) -> Eq FacetAttribute
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]
(Int -> ReadS FacetAttribute)
-> ReadS [FacetAttribute]
-> ReadPrec FacetAttribute
-> ReadPrec [FacetAttribute]
-> Read 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
(Int -> FacetAttribute -> ShowS)
-> (FacetAttribute -> String)
-> ([FacetAttribute] -> ShowS)
-> Show FacetAttribute
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. FacetAttribute -> Rep FacetAttribute x)
-> (forall x. Rep FacetAttribute x -> FacetAttribute)
-> Generic FacetAttribute
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:
--
-- '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.
--
-- '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.
--
-- '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' :: Maybe FacetAttributeReference
-> Maybe FacetAttributeDefinition
-> Maybe RequiredAttributeBehavior
-> Text
-> FacetAttribute
FacetAttribute'
    { $sel:attributeReference:FacetAttribute' :: Maybe FacetAttributeReference
attributeReference =
        Maybe FacetAttributeReference
forall a. Maybe a
Prelude.Nothing,
      $sel:attributeDefinition:FacetAttribute' :: Maybe FacetAttributeDefinition
attributeDefinition = Maybe FacetAttributeDefinition
forall a. Maybe a
Prelude.Nothing,
      $sel:requiredBehavior:FacetAttribute' :: Maybe RequiredAttributeBehavior
requiredBehavior = Maybe RequiredAttributeBehavior
forall a. Maybe a
Prelude.Nothing,
      $sel:name:FacetAttribute' :: Text
name = Text
pName_
    }

-- | 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 :: (Maybe FacetAttributeReference
 -> f (Maybe FacetAttributeReference))
-> FacetAttribute -> f FacetAttribute
facetAttribute_attributeReference = (FacetAttribute -> Maybe FacetAttributeReference)
-> (FacetAttribute
    -> Maybe FacetAttributeReference -> FacetAttribute)
-> Lens
     FacetAttribute
     FacetAttribute
     (Maybe FacetAttributeReference)
     (Maybe FacetAttributeReference)
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)

-- | 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 :: (Maybe FacetAttributeDefinition
 -> f (Maybe FacetAttributeDefinition))
-> FacetAttribute -> f FacetAttribute
facetAttribute_attributeDefinition = (FacetAttribute -> Maybe FacetAttributeDefinition)
-> (FacetAttribute
    -> Maybe FacetAttributeDefinition -> FacetAttribute)
-> Lens
     FacetAttribute
     FacetAttribute
     (Maybe FacetAttributeDefinition)
     (Maybe FacetAttributeDefinition)
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)

-- | The required behavior of the @FacetAttribute@.
facetAttribute_requiredBehavior :: Lens.Lens' FacetAttribute (Prelude.Maybe RequiredAttributeBehavior)
facetAttribute_requiredBehavior :: (Maybe RequiredAttributeBehavior
 -> f (Maybe RequiredAttributeBehavior))
-> FacetAttribute -> f FacetAttribute
facetAttribute_requiredBehavior = (FacetAttribute -> Maybe RequiredAttributeBehavior)
-> (FacetAttribute
    -> Maybe RequiredAttributeBehavior -> FacetAttribute)
-> Lens
     FacetAttribute
     FacetAttribute
     (Maybe RequiredAttributeBehavior)
     (Maybe RequiredAttributeBehavior)
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 :: (Text -> f Text) -> FacetAttribute -> f FacetAttribute
facetAttribute_name = (FacetAttribute -> Text)
-> (FacetAttribute -> Text -> FacetAttribute)
-> Lens FacetAttribute FacetAttribute Text Text
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 Core.FromJSON FacetAttribute where
  parseJSON :: Value -> Parser FacetAttribute
parseJSON =
    String
-> (Object -> Parser FacetAttribute)
-> Value
-> Parser FacetAttribute
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FacetAttribute"
      ( \Object
x ->
          Maybe FacetAttributeReference
-> Maybe FacetAttributeDefinition
-> Maybe RequiredAttributeBehavior
-> Text
-> FacetAttribute
FacetAttribute'
            (Maybe FacetAttributeReference
 -> Maybe FacetAttributeDefinition
 -> Maybe RequiredAttributeBehavior
 -> Text
 -> FacetAttribute)
-> Parser (Maybe FacetAttributeReference)
-> Parser
     (Maybe FacetAttributeDefinition
      -> Maybe RequiredAttributeBehavior -> Text -> FacetAttribute)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe FacetAttributeReference)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AttributeReference")
            Parser
  (Maybe FacetAttributeDefinition
   -> Maybe RequiredAttributeBehavior -> Text -> FacetAttribute)
-> Parser (Maybe FacetAttributeDefinition)
-> Parser
     (Maybe RequiredAttributeBehavior -> Text -> FacetAttribute)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe FacetAttributeDefinition)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AttributeDefinition")
            Parser (Maybe RequiredAttributeBehavior -> Text -> FacetAttribute)
-> Parser (Maybe RequiredAttributeBehavior)
-> Parser (Text -> FacetAttribute)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe RequiredAttributeBehavior)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RequiredBehavior")
            Parser (Text -> FacetAttribute)
-> Parser Text -> Parser FacetAttribute
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name")
      )

instance Prelude.Hashable FacetAttribute

instance Prelude.NFData FacetAttribute

instance Core.ToJSON FacetAttribute where
  toJSON :: FacetAttribute -> Value
toJSON FacetAttribute' {Maybe FacetAttributeReference
Maybe RequiredAttributeBehavior
Maybe FacetAttributeDefinition
Text
name :: Text
requiredBehavior :: Maybe RequiredAttributeBehavior
attributeDefinition :: Maybe FacetAttributeDefinition
attributeReference :: Maybe FacetAttributeReference
$sel:name:FacetAttribute' :: FacetAttribute -> Text
$sel:requiredBehavior:FacetAttribute' :: FacetAttribute -> Maybe RequiredAttributeBehavior
$sel:attributeDefinition:FacetAttribute' :: FacetAttribute -> Maybe FacetAttributeDefinition
$sel:attributeReference:FacetAttribute' :: FacetAttribute -> Maybe FacetAttributeReference
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AttributeReference" Text -> FacetAttributeReference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (FacetAttributeReference -> Pair)
-> Maybe FacetAttributeReference -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FacetAttributeReference
attributeReference,
            (Text
"AttributeDefinition" Text -> FacetAttributeDefinition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (FacetAttributeDefinition -> Pair)
-> Maybe FacetAttributeDefinition -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FacetAttributeDefinition
attributeDefinition,
            (Text
"RequiredBehavior" Text -> RequiredAttributeBehavior -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (RequiredAttributeBehavior -> Pair)
-> Maybe RequiredAttributeBehavior -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RequiredAttributeBehavior
requiredBehavior,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )