{-# 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.CloudDirectory.Types.ObjectReference
-- 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.CloudDirectory.Types.ObjectReference where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The reference that identifies an object.
--
-- /See:/ 'newObjectReference' smart constructor.
data ObjectReference = ObjectReference'
  { -- | A path selector supports easy selection of an object by the
    -- parent\/child links leading to it from the directory root. Use the link
    -- names from each parent\/child link to construct the path. Path selectors
    -- start with a slash (\/) and link names are separated by slashes. For
    -- more information about paths, see
    -- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/directory_objects_access_objects.html Access Objects>.
    -- You can identify an object in one of the following ways:
    --
    -- -   /$ObjectIdentifier/ - An object identifier is an opaque string
    --     provided by Amazon Cloud Directory. When creating objects, the
    --     system will provide you with the identifier of the created object.
    --     An object’s identifier is immutable and no two objects will ever
    --     share the same object identifier. To identify an object with
    --     ObjectIdentifier, the ObjectIdentifier must be wrapped in double
    --     quotes.
    --
    -- -   /\/some\/path/ - Identifies the object based on path
    --
    -- -   /#SomeBatchReference/ - Identifies the object in a batch call
    ObjectReference -> Maybe Text
selector :: Prelude.Maybe Prelude.Text
  }
  deriving (ObjectReference -> ObjectReference -> Bool
(ObjectReference -> ObjectReference -> Bool)
-> (ObjectReference -> ObjectReference -> Bool)
-> Eq ObjectReference
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ObjectReference -> ObjectReference -> Bool
$c/= :: ObjectReference -> ObjectReference -> Bool
== :: ObjectReference -> ObjectReference -> Bool
$c== :: ObjectReference -> ObjectReference -> Bool
Prelude.Eq, ReadPrec [ObjectReference]
ReadPrec ObjectReference
Int -> ReadS ObjectReference
ReadS [ObjectReference]
(Int -> ReadS ObjectReference)
-> ReadS [ObjectReference]
-> ReadPrec ObjectReference
-> ReadPrec [ObjectReference]
-> Read ObjectReference
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ObjectReference]
$creadListPrec :: ReadPrec [ObjectReference]
readPrec :: ReadPrec ObjectReference
$creadPrec :: ReadPrec ObjectReference
readList :: ReadS [ObjectReference]
$creadList :: ReadS [ObjectReference]
readsPrec :: Int -> ReadS ObjectReference
$creadsPrec :: Int -> ReadS ObjectReference
Prelude.Read, Int -> ObjectReference -> ShowS
[ObjectReference] -> ShowS
ObjectReference -> String
(Int -> ObjectReference -> ShowS)
-> (ObjectReference -> String)
-> ([ObjectReference] -> ShowS)
-> Show ObjectReference
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ObjectReference] -> ShowS
$cshowList :: [ObjectReference] -> ShowS
show :: ObjectReference -> String
$cshow :: ObjectReference -> String
showsPrec :: Int -> ObjectReference -> ShowS
$cshowsPrec :: Int -> ObjectReference -> ShowS
Prelude.Show, (forall x. ObjectReference -> Rep ObjectReference x)
-> (forall x. Rep ObjectReference x -> ObjectReference)
-> Generic ObjectReference
forall x. Rep ObjectReference x -> ObjectReference
forall x. ObjectReference -> Rep ObjectReference x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ObjectReference x -> ObjectReference
$cfrom :: forall x. ObjectReference -> Rep ObjectReference x
Prelude.Generic)

-- |
-- Create a value of 'ObjectReference' 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:
--
-- 'selector', 'objectReference_selector' - A path selector supports easy selection of an object by the
-- parent\/child links leading to it from the directory root. Use the link
-- names from each parent\/child link to construct the path. Path selectors
-- start with a slash (\/) and link names are separated by slashes. For
-- more information about paths, see
-- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/directory_objects_access_objects.html Access Objects>.
-- You can identify an object in one of the following ways:
--
-- -   /$ObjectIdentifier/ - An object identifier is an opaque string
--     provided by Amazon Cloud Directory. When creating objects, the
--     system will provide you with the identifier of the created object.
--     An object’s identifier is immutable and no two objects will ever
--     share the same object identifier. To identify an object with
--     ObjectIdentifier, the ObjectIdentifier must be wrapped in double
--     quotes.
--
-- -   /\/some\/path/ - Identifies the object based on path
--
-- -   /#SomeBatchReference/ - Identifies the object in a batch call
newObjectReference ::
  ObjectReference
newObjectReference :: ObjectReference
newObjectReference =
  ObjectReference' :: Maybe Text -> ObjectReference
ObjectReference' {$sel:selector:ObjectReference' :: Maybe Text
selector = Maybe Text
forall a. Maybe a
Prelude.Nothing}

-- | A path selector supports easy selection of an object by the
-- parent\/child links leading to it from the directory root. Use the link
-- names from each parent\/child link to construct the path. Path selectors
-- start with a slash (\/) and link names are separated by slashes. For
-- more information about paths, see
-- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/directory_objects_access_objects.html Access Objects>.
-- You can identify an object in one of the following ways:
--
-- -   /$ObjectIdentifier/ - An object identifier is an opaque string
--     provided by Amazon Cloud Directory. When creating objects, the
--     system will provide you with the identifier of the created object.
--     An object’s identifier is immutable and no two objects will ever
--     share the same object identifier. To identify an object with
--     ObjectIdentifier, the ObjectIdentifier must be wrapped in double
--     quotes.
--
-- -   /\/some\/path/ - Identifies the object based on path
--
-- -   /#SomeBatchReference/ - Identifies the object in a batch call
objectReference_selector :: Lens.Lens' ObjectReference (Prelude.Maybe Prelude.Text)
objectReference_selector :: (Maybe Text -> f (Maybe Text))
-> ObjectReference -> f ObjectReference
objectReference_selector = (ObjectReference -> Maybe Text)
-> (ObjectReference -> Maybe Text -> ObjectReference)
-> Lens ObjectReference ObjectReference (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObjectReference' {Maybe Text
selector :: Maybe Text
$sel:selector:ObjectReference' :: ObjectReference -> Maybe Text
selector} -> Maybe Text
selector) (\s :: ObjectReference
s@ObjectReference' {} Maybe Text
a -> ObjectReference
s {$sel:selector:ObjectReference' :: Maybe Text
selector = Maybe Text
a} :: ObjectReference)

instance Core.FromJSON ObjectReference where
  parseJSON :: Value -> Parser ObjectReference
parseJSON =
    String
-> (Object -> Parser ObjectReference)
-> Value
-> Parser ObjectReference
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ObjectReference"
      ( \Object
x ->
          Maybe Text -> ObjectReference
ObjectReference' (Maybe Text -> ObjectReference)
-> Parser (Maybe Text) -> Parser ObjectReference
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
"Selector")
      )

instance Prelude.Hashable ObjectReference

instance Prelude.NFData ObjectReference

instance Core.ToJSON ObjectReference where
  toJSON :: ObjectReference -> Value
toJSON ObjectReference' {Maybe Text
selector :: Maybe Text
$sel:selector:ObjectReference' :: ObjectReference -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Selector" 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
selector]
      )