{-# 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.MigrationHub.Types.ResourceAttribute
-- 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.MigrationHub.Types.ResourceAttribute where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MigrationHub.Types.ResourceAttributeType
import qualified Amazonka.Prelude as Prelude

-- | Attribute associated with a resource.
--
-- Note the corresponding format required per type listed below:
--
-- [IPV4]
--     @x.x.x.x@
--
--     /where x is an integer in the range [0,255]/
--
-- [IPV6]
--     @y : y : y : y : y : y : y : y@
--
--     /where y is a hexadecimal between 0 and FFFF. [0, FFFF]/
--
-- [MAC_ADDRESS]
--     @^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$@
--
-- [FQDN]
--     @^[^\<>{}\\\\\\\\\/?,=\\\\p{Cntrl}]{1,256}$@
--
-- /See:/ 'newResourceAttribute' smart constructor.
data ResourceAttribute = ResourceAttribute'
  { -- | Type of resource.
    ResourceAttribute -> ResourceAttributeType
type' :: ResourceAttributeType,
    -- | Value of the resource type.
    ResourceAttribute -> Text
value :: Prelude.Text
  }
  deriving (ResourceAttribute -> ResourceAttribute -> Bool
(ResourceAttribute -> ResourceAttribute -> Bool)
-> (ResourceAttribute -> ResourceAttribute -> Bool)
-> Eq ResourceAttribute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceAttribute -> ResourceAttribute -> Bool
$c/= :: ResourceAttribute -> ResourceAttribute -> Bool
== :: ResourceAttribute -> ResourceAttribute -> Bool
$c== :: ResourceAttribute -> ResourceAttribute -> Bool
Prelude.Eq, ReadPrec [ResourceAttribute]
ReadPrec ResourceAttribute
Int -> ReadS ResourceAttribute
ReadS [ResourceAttribute]
(Int -> ReadS ResourceAttribute)
-> ReadS [ResourceAttribute]
-> ReadPrec ResourceAttribute
-> ReadPrec [ResourceAttribute]
-> Read ResourceAttribute
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceAttribute]
$creadListPrec :: ReadPrec [ResourceAttribute]
readPrec :: ReadPrec ResourceAttribute
$creadPrec :: ReadPrec ResourceAttribute
readList :: ReadS [ResourceAttribute]
$creadList :: ReadS [ResourceAttribute]
readsPrec :: Int -> ReadS ResourceAttribute
$creadsPrec :: Int -> ReadS ResourceAttribute
Prelude.Read, Int -> ResourceAttribute -> ShowS
[ResourceAttribute] -> ShowS
ResourceAttribute -> String
(Int -> ResourceAttribute -> ShowS)
-> (ResourceAttribute -> String)
-> ([ResourceAttribute] -> ShowS)
-> Show ResourceAttribute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceAttribute] -> ShowS
$cshowList :: [ResourceAttribute] -> ShowS
show :: ResourceAttribute -> String
$cshow :: ResourceAttribute -> String
showsPrec :: Int -> ResourceAttribute -> ShowS
$cshowsPrec :: Int -> ResourceAttribute -> ShowS
Prelude.Show, (forall x. ResourceAttribute -> Rep ResourceAttribute x)
-> (forall x. Rep ResourceAttribute x -> ResourceAttribute)
-> Generic ResourceAttribute
forall x. Rep ResourceAttribute x -> ResourceAttribute
forall x. ResourceAttribute -> Rep ResourceAttribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourceAttribute x -> ResourceAttribute
$cfrom :: forall x. ResourceAttribute -> Rep ResourceAttribute x
Prelude.Generic)

-- |
-- Create a value of 'ResourceAttribute' 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:
--
-- 'type'', 'resourceAttribute_type' - Type of resource.
--
-- 'value', 'resourceAttribute_value' - Value of the resource type.
newResourceAttribute ::
  -- | 'type''
  ResourceAttributeType ->
  -- | 'value'
  Prelude.Text ->
  ResourceAttribute
newResourceAttribute :: ResourceAttributeType -> Text -> ResourceAttribute
newResourceAttribute ResourceAttributeType
pType_ Text
pValue_ =
  ResourceAttribute' :: ResourceAttributeType -> Text -> ResourceAttribute
ResourceAttribute' {$sel:type':ResourceAttribute' :: ResourceAttributeType
type' = ResourceAttributeType
pType_, $sel:value:ResourceAttribute' :: Text
value = Text
pValue_}

-- | Type of resource.
resourceAttribute_type :: Lens.Lens' ResourceAttribute ResourceAttributeType
resourceAttribute_type :: (ResourceAttributeType -> f ResourceAttributeType)
-> ResourceAttribute -> f ResourceAttribute
resourceAttribute_type = (ResourceAttribute -> ResourceAttributeType)
-> (ResourceAttribute
    -> ResourceAttributeType -> ResourceAttribute)
-> Lens
     ResourceAttribute
     ResourceAttribute
     ResourceAttributeType
     ResourceAttributeType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceAttribute' {ResourceAttributeType
type' :: ResourceAttributeType
$sel:type':ResourceAttribute' :: ResourceAttribute -> ResourceAttributeType
type'} -> ResourceAttributeType
type') (\s :: ResourceAttribute
s@ResourceAttribute' {} ResourceAttributeType
a -> ResourceAttribute
s {$sel:type':ResourceAttribute' :: ResourceAttributeType
type' = ResourceAttributeType
a} :: ResourceAttribute)

-- | Value of the resource type.
resourceAttribute_value :: Lens.Lens' ResourceAttribute Prelude.Text
resourceAttribute_value :: (Text -> f Text) -> ResourceAttribute -> f ResourceAttribute
resourceAttribute_value = (ResourceAttribute -> Text)
-> (ResourceAttribute -> Text -> ResourceAttribute)
-> Lens ResourceAttribute ResourceAttribute Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceAttribute' {Text
value :: Text
$sel:value:ResourceAttribute' :: ResourceAttribute -> Text
value} -> Text
value) (\s :: ResourceAttribute
s@ResourceAttribute' {} Text
a -> ResourceAttribute
s {$sel:value:ResourceAttribute' :: Text
value = Text
a} :: ResourceAttribute)

instance Core.FromJSON ResourceAttribute where
  parseJSON :: Value -> Parser ResourceAttribute
parseJSON =
    String
-> (Object -> Parser ResourceAttribute)
-> Value
-> Parser ResourceAttribute
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResourceAttribute"
      ( \Object
x ->
          ResourceAttributeType -> Text -> ResourceAttribute
ResourceAttribute'
            (ResourceAttributeType -> Text -> ResourceAttribute)
-> Parser ResourceAttributeType
-> Parser (Text -> ResourceAttribute)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser ResourceAttributeType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type") Parser (Text -> ResourceAttribute)
-> Parser Text -> Parser ResourceAttribute
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
"Value")
      )

instance Prelude.Hashable ResourceAttribute

instance Prelude.NFData ResourceAttribute

instance Core.ToJSON ResourceAttribute where
  toJSON :: ResourceAttribute -> Value
toJSON ResourceAttribute' {Text
ResourceAttributeType
value :: Text
type' :: ResourceAttributeType
$sel:value:ResourceAttribute' :: ResourceAttribute -> Text
$sel:type':ResourceAttribute' :: ResourceAttribute -> ResourceAttributeType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> ResourceAttributeType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ResourceAttributeType
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value)
          ]
      )