{-# 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.LakeFormation.Types.LFTagPolicyResource
-- 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.LakeFormation.Types.LFTagPolicyResource where

import qualified Amazonka.Core as Core
import Amazonka.LakeFormation.Types.LFTag
import Amazonka.LakeFormation.Types.ResourceType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A structure containing a list of tag conditions that apply to a
-- resource\'s tag policy.
--
-- /See:/ 'newLFTagPolicyResource' smart constructor.
data LFTagPolicyResource = LFTagPolicyResource'
  { -- | The identifier for the Data Catalog. By default, the account ID. The
    -- Data Catalog is the persistent metadata store. It contains database
    -- definitions, table definitions, and other control information to manage
    -- your AWS Lake Formation environment.
    LFTagPolicyResource -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The resource type for which the tag policy applies.
    LFTagPolicyResource -> ResourceType
resourceType :: ResourceType,
    -- | A list of tag conditions that apply to the resource\'s tag policy.
    LFTagPolicyResource -> NonEmpty LFTag
expression :: Prelude.NonEmpty LFTag
  }
  deriving (LFTagPolicyResource -> LFTagPolicyResource -> Bool
(LFTagPolicyResource -> LFTagPolicyResource -> Bool)
-> (LFTagPolicyResource -> LFTagPolicyResource -> Bool)
-> Eq LFTagPolicyResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LFTagPolicyResource -> LFTagPolicyResource -> Bool
$c/= :: LFTagPolicyResource -> LFTagPolicyResource -> Bool
== :: LFTagPolicyResource -> LFTagPolicyResource -> Bool
$c== :: LFTagPolicyResource -> LFTagPolicyResource -> Bool
Prelude.Eq, ReadPrec [LFTagPolicyResource]
ReadPrec LFTagPolicyResource
Int -> ReadS LFTagPolicyResource
ReadS [LFTagPolicyResource]
(Int -> ReadS LFTagPolicyResource)
-> ReadS [LFTagPolicyResource]
-> ReadPrec LFTagPolicyResource
-> ReadPrec [LFTagPolicyResource]
-> Read LFTagPolicyResource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LFTagPolicyResource]
$creadListPrec :: ReadPrec [LFTagPolicyResource]
readPrec :: ReadPrec LFTagPolicyResource
$creadPrec :: ReadPrec LFTagPolicyResource
readList :: ReadS [LFTagPolicyResource]
$creadList :: ReadS [LFTagPolicyResource]
readsPrec :: Int -> ReadS LFTagPolicyResource
$creadsPrec :: Int -> ReadS LFTagPolicyResource
Prelude.Read, Int -> LFTagPolicyResource -> ShowS
[LFTagPolicyResource] -> ShowS
LFTagPolicyResource -> String
(Int -> LFTagPolicyResource -> ShowS)
-> (LFTagPolicyResource -> String)
-> ([LFTagPolicyResource] -> ShowS)
-> Show LFTagPolicyResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LFTagPolicyResource] -> ShowS
$cshowList :: [LFTagPolicyResource] -> ShowS
show :: LFTagPolicyResource -> String
$cshow :: LFTagPolicyResource -> String
showsPrec :: Int -> LFTagPolicyResource -> ShowS
$cshowsPrec :: Int -> LFTagPolicyResource -> ShowS
Prelude.Show, (forall x. LFTagPolicyResource -> Rep LFTagPolicyResource x)
-> (forall x. Rep LFTagPolicyResource x -> LFTagPolicyResource)
-> Generic LFTagPolicyResource
forall x. Rep LFTagPolicyResource x -> LFTagPolicyResource
forall x. LFTagPolicyResource -> Rep LFTagPolicyResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LFTagPolicyResource x -> LFTagPolicyResource
$cfrom :: forall x. LFTagPolicyResource -> Rep LFTagPolicyResource x
Prelude.Generic)

-- |
-- Create a value of 'LFTagPolicyResource' 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:
--
-- 'catalogId', 'lFTagPolicyResource_catalogId' - The identifier for the Data Catalog. By default, the account ID. The
-- Data Catalog is the persistent metadata store. It contains database
-- definitions, table definitions, and other control information to manage
-- your AWS Lake Formation environment.
--
-- 'resourceType', 'lFTagPolicyResource_resourceType' - The resource type for which the tag policy applies.
--
-- 'expression', 'lFTagPolicyResource_expression' - A list of tag conditions that apply to the resource\'s tag policy.
newLFTagPolicyResource ::
  -- | 'resourceType'
  ResourceType ->
  -- | 'expression'
  Prelude.NonEmpty LFTag ->
  LFTagPolicyResource
newLFTagPolicyResource :: ResourceType -> NonEmpty LFTag -> LFTagPolicyResource
newLFTagPolicyResource ResourceType
pResourceType_ NonEmpty LFTag
pExpression_ =
  LFTagPolicyResource' :: Maybe Text -> ResourceType -> NonEmpty LFTag -> LFTagPolicyResource
LFTagPolicyResource'
    { $sel:catalogId:LFTagPolicyResource' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceType:LFTagPolicyResource' :: ResourceType
resourceType = ResourceType
pResourceType_,
      $sel:expression:LFTagPolicyResource' :: NonEmpty LFTag
expression = Tagged (NonEmpty LFTag) (Identity (NonEmpty LFTag))
-> Tagged (NonEmpty LFTag) (Identity (NonEmpty LFTag))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty LFTag) (Identity (NonEmpty LFTag))
 -> Tagged (NonEmpty LFTag) (Identity (NonEmpty LFTag)))
-> NonEmpty LFTag -> NonEmpty LFTag
forall t b. AReview t b -> b -> t
Lens.# NonEmpty LFTag
pExpression_
    }

-- | The identifier for the Data Catalog. By default, the account ID. The
-- Data Catalog is the persistent metadata store. It contains database
-- definitions, table definitions, and other control information to manage
-- your AWS Lake Formation environment.
lFTagPolicyResource_catalogId :: Lens.Lens' LFTagPolicyResource (Prelude.Maybe Prelude.Text)
lFTagPolicyResource_catalogId :: (Maybe Text -> f (Maybe Text))
-> LFTagPolicyResource -> f LFTagPolicyResource
lFTagPolicyResource_catalogId = (LFTagPolicyResource -> Maybe Text)
-> (LFTagPolicyResource -> Maybe Text -> LFTagPolicyResource)
-> Lens
     LFTagPolicyResource LFTagPolicyResource (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LFTagPolicyResource' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:LFTagPolicyResource' :: LFTagPolicyResource -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: LFTagPolicyResource
s@LFTagPolicyResource' {} Maybe Text
a -> LFTagPolicyResource
s {$sel:catalogId:LFTagPolicyResource' :: Maybe Text
catalogId = Maybe Text
a} :: LFTagPolicyResource)

-- | The resource type for which the tag policy applies.
lFTagPolicyResource_resourceType :: Lens.Lens' LFTagPolicyResource ResourceType
lFTagPolicyResource_resourceType :: (ResourceType -> f ResourceType)
-> LFTagPolicyResource -> f LFTagPolicyResource
lFTagPolicyResource_resourceType = (LFTagPolicyResource -> ResourceType)
-> (LFTagPolicyResource -> ResourceType -> LFTagPolicyResource)
-> Lens
     LFTagPolicyResource LFTagPolicyResource ResourceType ResourceType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LFTagPolicyResource' {ResourceType
resourceType :: ResourceType
$sel:resourceType:LFTagPolicyResource' :: LFTagPolicyResource -> ResourceType
resourceType} -> ResourceType
resourceType) (\s :: LFTagPolicyResource
s@LFTagPolicyResource' {} ResourceType
a -> LFTagPolicyResource
s {$sel:resourceType:LFTagPolicyResource' :: ResourceType
resourceType = ResourceType
a} :: LFTagPolicyResource)

-- | A list of tag conditions that apply to the resource\'s tag policy.
lFTagPolicyResource_expression :: Lens.Lens' LFTagPolicyResource (Prelude.NonEmpty LFTag)
lFTagPolicyResource_expression :: (NonEmpty LFTag -> f (NonEmpty LFTag))
-> LFTagPolicyResource -> f LFTagPolicyResource
lFTagPolicyResource_expression = (LFTagPolicyResource -> NonEmpty LFTag)
-> (LFTagPolicyResource -> NonEmpty LFTag -> LFTagPolicyResource)
-> Lens
     LFTagPolicyResource
     LFTagPolicyResource
     (NonEmpty LFTag)
     (NonEmpty LFTag)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LFTagPolicyResource' {NonEmpty LFTag
expression :: NonEmpty LFTag
$sel:expression:LFTagPolicyResource' :: LFTagPolicyResource -> NonEmpty LFTag
expression} -> NonEmpty LFTag
expression) (\s :: LFTagPolicyResource
s@LFTagPolicyResource' {} NonEmpty LFTag
a -> LFTagPolicyResource
s {$sel:expression:LFTagPolicyResource' :: NonEmpty LFTag
expression = NonEmpty LFTag
a} :: LFTagPolicyResource) ((NonEmpty LFTag -> f (NonEmpty LFTag))
 -> LFTagPolicyResource -> f LFTagPolicyResource)
-> ((NonEmpty LFTag -> f (NonEmpty LFTag))
    -> NonEmpty LFTag -> f (NonEmpty LFTag))
-> (NonEmpty LFTag -> f (NonEmpty LFTag))
-> LFTagPolicyResource
-> f LFTagPolicyResource
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty LFTag -> f (NonEmpty LFTag))
-> NonEmpty LFTag -> f (NonEmpty LFTag)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON LFTagPolicyResource where
  parseJSON :: Value -> Parser LFTagPolicyResource
parseJSON =
    String
-> (Object -> Parser LFTagPolicyResource)
-> Value
-> Parser LFTagPolicyResource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LFTagPolicyResource"
      ( \Object
x ->
          Maybe Text -> ResourceType -> NonEmpty LFTag -> LFTagPolicyResource
LFTagPolicyResource'
            (Maybe Text
 -> ResourceType -> NonEmpty LFTag -> LFTagPolicyResource)
-> Parser (Maybe Text)
-> Parser (ResourceType -> NonEmpty LFTag -> LFTagPolicyResource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CatalogId")
            Parser (ResourceType -> NonEmpty LFTag -> LFTagPolicyResource)
-> Parser ResourceType
-> Parser (NonEmpty LFTag -> LFTagPolicyResource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ResourceType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ResourceType")
            Parser (NonEmpty LFTag -> LFTagPolicyResource)
-> Parser (NonEmpty LFTag) -> Parser LFTagPolicyResource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty LFTag)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Expression")
      )

instance Prelude.Hashable LFTagPolicyResource

instance Prelude.NFData LFTagPolicyResource

instance Core.ToJSON LFTagPolicyResource where
  toJSON :: LFTagPolicyResource -> Value
toJSON LFTagPolicyResource' {Maybe Text
NonEmpty LFTag
ResourceType
expression :: NonEmpty LFTag
resourceType :: ResourceType
catalogId :: Maybe Text
$sel:expression:LFTagPolicyResource' :: LFTagPolicyResource -> NonEmpty LFTag
$sel:resourceType:LFTagPolicyResource' :: LFTagPolicyResource -> ResourceType
$sel:catalogId:LFTagPolicyResource' :: LFTagPolicyResource -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CatalogId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
catalogId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ResourceType" Text -> ResourceType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ResourceType
resourceType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Expression" Text -> NonEmpty LFTag -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty LFTag
expression)
          ]
      )