{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.MigrationHub.Types.ResourceAttribute where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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' {$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 :: Lens' ResourceAttribute ResourceAttributeType
resourceAttribute_type = 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 :: Lens' ResourceAttribute Text
resourceAttribute_value = 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 Data.FromJSON ResourceAttribute where
  parseJSON :: Value -> Parser ResourceAttribute
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ResourceAttribute"
      ( \Object
x ->
          ResourceAttributeType -> Text -> ResourceAttribute
ResourceAttribute'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Type")
            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
"Value")
      )

instance Prelude.Hashable ResourceAttribute where
  hashWithSalt :: Int -> ResourceAttribute -> Int
hashWithSalt Int
_salt ResourceAttribute' {Text
ResourceAttributeType
value :: Text
type' :: ResourceAttributeType
$sel:value:ResourceAttribute' :: ResourceAttribute -> Text
$sel:type':ResourceAttribute' :: ResourceAttribute -> ResourceAttributeType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ResourceAttributeType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value

instance Prelude.NFData ResourceAttribute where
  rnf :: ResourceAttribute -> ()
rnf ResourceAttribute' {Text
ResourceAttributeType
value :: Text
type' :: ResourceAttributeType
$sel:value:ResourceAttribute' :: ResourceAttribute -> Text
$sel:type':ResourceAttribute' :: ResourceAttribute -> ResourceAttributeType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf ResourceAttributeType
type' seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
value

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ResourceAttributeType
type'),
            forall a. a -> Maybe a
Prelude.Just (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
value)
          ]
      )