{-# 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.Organizations.Types.Child
-- 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.Organizations.Types.Child where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Organizations.Types.ChildType
import qualified Amazonka.Prelude as Prelude

-- | Contains a list of child entities, either OUs or accounts.
--
-- /See:/ 'newChild' smart constructor.
data Child = Child'
  { -- | The unique identifier (ID) of this child entity.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> for a child ID
    -- string requires one of the following:
    --
    -- -   __Account__ - A string that consists of exactly 12 digits.
    --
    -- -   __Organizational unit (OU)__ - A string that begins with \"ou-\"
    --     followed by from 4 to 32 lowercase letters or digits (the ID of the
    --     root that contains the OU). This string is followed by a second
    --     \"-\" dash and from 8 to 32 additional lowercase letters or digits.
    Child -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The type of this child entity.
    Child -> Maybe ChildType
type' :: Prelude.Maybe ChildType
  }
  deriving (Child -> Child -> Bool
(Child -> Child -> Bool) -> (Child -> Child -> Bool) -> Eq Child
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Child -> Child -> Bool
$c/= :: Child -> Child -> Bool
== :: Child -> Child -> Bool
$c== :: Child -> Child -> Bool
Prelude.Eq, ReadPrec [Child]
ReadPrec Child
Int -> ReadS Child
ReadS [Child]
(Int -> ReadS Child)
-> ReadS [Child]
-> ReadPrec Child
-> ReadPrec [Child]
-> Read Child
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Child]
$creadListPrec :: ReadPrec [Child]
readPrec :: ReadPrec Child
$creadPrec :: ReadPrec Child
readList :: ReadS [Child]
$creadList :: ReadS [Child]
readsPrec :: Int -> ReadS Child
$creadsPrec :: Int -> ReadS Child
Prelude.Read, Int -> Child -> ShowS
[Child] -> ShowS
Child -> String
(Int -> Child -> ShowS)
-> (Child -> String) -> ([Child] -> ShowS) -> Show Child
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Child] -> ShowS
$cshowList :: [Child] -> ShowS
show :: Child -> String
$cshow :: Child -> String
showsPrec :: Int -> Child -> ShowS
$cshowsPrec :: Int -> Child -> ShowS
Prelude.Show, (forall x. Child -> Rep Child x)
-> (forall x. Rep Child x -> Child) -> Generic Child
forall x. Rep Child x -> Child
forall x. Child -> Rep Child x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Child x -> Child
$cfrom :: forall x. Child -> Rep Child x
Prelude.Generic)

-- |
-- Create a value of 'Child' 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', 'child_id' - The unique identifier (ID) of this child entity.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a child ID
-- string requires one of the following:
--
-- -   __Account__ - A string that consists of exactly 12 digits.
--
-- -   __Organizational unit (OU)__ - A string that begins with \"ou-\"
--     followed by from 4 to 32 lowercase letters or digits (the ID of the
--     root that contains the OU). This string is followed by a second
--     \"-\" dash and from 8 to 32 additional lowercase letters or digits.
--
-- 'type'', 'child_type' - The type of this child entity.
newChild ::
  Child
newChild :: Child
newChild =
  Child' :: Maybe Text -> Maybe ChildType -> Child
Child'
    { $sel:id:Child' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':Child' :: Maybe ChildType
type' = Maybe ChildType
forall a. Maybe a
Prelude.Nothing
    }

-- | The unique identifier (ID) of this child entity.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a child ID
-- string requires one of the following:
--
-- -   __Account__ - A string that consists of exactly 12 digits.
--
-- -   __Organizational unit (OU)__ - A string that begins with \"ou-\"
--     followed by from 4 to 32 lowercase letters or digits (the ID of the
--     root that contains the OU). This string is followed by a second
--     \"-\" dash and from 8 to 32 additional lowercase letters or digits.
child_id :: Lens.Lens' Child (Prelude.Maybe Prelude.Text)
child_id :: (Maybe Text -> f (Maybe Text)) -> Child -> f Child
child_id = (Child -> Maybe Text)
-> (Child -> Maybe Text -> Child)
-> Lens Child Child (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Child' {Maybe Text
id :: Maybe Text
$sel:id:Child' :: Child -> Maybe Text
id} -> Maybe Text
id) (\s :: Child
s@Child' {} Maybe Text
a -> Child
s {$sel:id:Child' :: Maybe Text
id = Maybe Text
a} :: Child)

-- | The type of this child entity.
child_type :: Lens.Lens' Child (Prelude.Maybe ChildType)
child_type :: (Maybe ChildType -> f (Maybe ChildType)) -> Child -> f Child
child_type = (Child -> Maybe ChildType)
-> (Child -> Maybe ChildType -> Child)
-> Lens Child Child (Maybe ChildType) (Maybe ChildType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Child' {Maybe ChildType
type' :: Maybe ChildType
$sel:type':Child' :: Child -> Maybe ChildType
type'} -> Maybe ChildType
type') (\s :: Child
s@Child' {} Maybe ChildType
a -> Child
s {$sel:type':Child' :: Maybe ChildType
type' = Maybe ChildType
a} :: Child)

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

instance Prelude.Hashable Child

instance Prelude.NFData Child