{-# 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.MigrationHubConfig.Types.Target
-- 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.MigrationHubConfig.Types.Target where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MigrationHubConfig.Types.TargetType
import qualified Amazonka.Prelude as Prelude

-- | The target parameter specifies the identifier to which the home region
-- is applied, which is always an @ACCOUNT@. It applies the home region to
-- the current @ACCOUNT@.
--
-- /See:/ 'newTarget' smart constructor.
data Target = Target'
  { -- | The @TargetID@ is a 12-character identifier of the @ACCOUNT@ for which
    -- the control was created. (This must be the current account.)
    Target -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The target type is always an @ACCOUNT@.
    Target -> TargetType
type' :: TargetType
  }
  deriving (Target -> Target -> Bool
(Target -> Target -> Bool)
-> (Target -> Target -> Bool) -> Eq Target
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Target -> Target -> Bool
$c/= :: Target -> Target -> Bool
== :: Target -> Target -> Bool
$c== :: Target -> Target -> Bool
Prelude.Eq, ReadPrec [Target]
ReadPrec Target
Int -> ReadS Target
ReadS [Target]
(Int -> ReadS Target)
-> ReadS [Target]
-> ReadPrec Target
-> ReadPrec [Target]
-> Read Target
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Target]
$creadListPrec :: ReadPrec [Target]
readPrec :: ReadPrec Target
$creadPrec :: ReadPrec Target
readList :: ReadS [Target]
$creadList :: ReadS [Target]
readsPrec :: Int -> ReadS Target
$creadsPrec :: Int -> ReadS Target
Prelude.Read, Int -> Target -> ShowS
[Target] -> ShowS
Target -> String
(Int -> Target -> ShowS)
-> (Target -> String) -> ([Target] -> ShowS) -> Show Target
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Target] -> ShowS
$cshowList :: [Target] -> ShowS
show :: Target -> String
$cshow :: Target -> String
showsPrec :: Int -> Target -> ShowS
$cshowsPrec :: Int -> Target -> ShowS
Prelude.Show, (forall x. Target -> Rep Target x)
-> (forall x. Rep Target x -> Target) -> Generic Target
forall x. Rep Target x -> Target
forall x. Target -> Rep Target x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Target x -> Target
$cfrom :: forall x. Target -> Rep Target x
Prelude.Generic)

-- |
-- Create a value of 'Target' 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:
--
-- 'id', 'target_id' - The @TargetID@ is a 12-character identifier of the @ACCOUNT@ for which
-- the control was created. (This must be the current account.)
--
-- 'type'', 'target_type' - The target type is always an @ACCOUNT@.
newTarget ::
  -- | 'type''
  TargetType ->
  Target
newTarget :: TargetType -> Target
newTarget TargetType
pType_ =
  Target' :: Maybe Text -> TargetType -> Target
Target' {$sel:id:Target' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing, $sel:type':Target' :: TargetType
type' = TargetType
pType_}

-- | The @TargetID@ is a 12-character identifier of the @ACCOUNT@ for which
-- the control was created. (This must be the current account.)
target_id :: Lens.Lens' Target (Prelude.Maybe Prelude.Text)
target_id :: (Maybe Text -> f (Maybe Text)) -> Target -> f Target
target_id = (Target -> Maybe Text)
-> (Target -> Maybe Text -> Target)
-> Lens Target Target (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Target' {Maybe Text
id :: Maybe Text
$sel:id:Target' :: Target -> Maybe Text
id} -> Maybe Text
id) (\s :: Target
s@Target' {} Maybe Text
a -> Target
s {$sel:id:Target' :: Maybe Text
id = Maybe Text
a} :: Target)

-- | The target type is always an @ACCOUNT@.
target_type :: Lens.Lens' Target TargetType
target_type :: (TargetType -> f TargetType) -> Target -> f Target
target_type = (Target -> TargetType)
-> (Target -> TargetType -> Target)
-> Lens Target Target TargetType TargetType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Target' {TargetType
type' :: TargetType
$sel:type':Target' :: Target -> TargetType
type'} -> TargetType
type') (\s :: Target
s@Target' {} TargetType
a -> Target
s {$sel:type':Target' :: TargetType
type' = TargetType
a} :: Target)

instance Core.FromJSON Target where
  parseJSON :: Value -> Parser Target
parseJSON =
    String -> (Object -> Parser Target) -> Value -> Parser Target
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Target"
      ( \Object
x ->
          Maybe Text -> TargetType -> Target
Target'
            (Maybe Text -> TargetType -> Target)
-> Parser (Maybe Text) -> Parser (TargetType -> Target)
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
"Id") Parser (TargetType -> Target) -> Parser TargetType -> Parser Target
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser TargetType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type")
      )

instance Prelude.Hashable Target

instance Prelude.NFData Target

instance Core.ToJSON Target where
  toJSON :: Target -> Value
toJSON Target' {Maybe Text
TargetType
type' :: TargetType
id :: Maybe Text
$sel:type':Target' :: Target -> TargetType
$sel:id:Target' :: Target -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Id" 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
id,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> TargetType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= TargetType
type')
          ]
      )