{-# 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.XRay.Types.Segment
-- 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.XRay.Types.Segment where

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

-- | A segment from a trace that has been ingested by the X-Ray service. The
-- segment can be compiled from documents uploaded with
-- <https://docs.aws.amazon.com/xray/latest/api/API_PutTraceSegments.html PutTraceSegments>,
-- or an @inferred@ segment for a downstream service, generated from a
-- subsegment sent by the service that called it.
--
-- For the full segment document schema, see
-- <https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html Amazon Web Services X-Ray Segment Documents>
-- in the /Amazon Web Services X-Ray Developer Guide/.
--
-- /See:/ 'newSegment' smart constructor.
data Segment = Segment'
  { -- | The segment document.
    Segment -> Maybe Text
document :: Prelude.Maybe Prelude.Text,
    -- | The segment\'s ID.
    Segment -> Maybe Text
id :: Prelude.Maybe Prelude.Text
  }
  deriving (Segment -> Segment -> Bool
(Segment -> Segment -> Bool)
-> (Segment -> Segment -> Bool) -> Eq Segment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Segment -> Segment -> Bool
$c/= :: Segment -> Segment -> Bool
== :: Segment -> Segment -> Bool
$c== :: Segment -> Segment -> Bool
Prelude.Eq, ReadPrec [Segment]
ReadPrec Segment
Int -> ReadS Segment
ReadS [Segment]
(Int -> ReadS Segment)
-> ReadS [Segment]
-> ReadPrec Segment
-> ReadPrec [Segment]
-> Read Segment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Segment]
$creadListPrec :: ReadPrec [Segment]
readPrec :: ReadPrec Segment
$creadPrec :: ReadPrec Segment
readList :: ReadS [Segment]
$creadList :: ReadS [Segment]
readsPrec :: Int -> ReadS Segment
$creadsPrec :: Int -> ReadS Segment
Prelude.Read, Int -> Segment -> ShowS
[Segment] -> ShowS
Segment -> String
(Int -> Segment -> ShowS)
-> (Segment -> String) -> ([Segment] -> ShowS) -> Show Segment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Segment] -> ShowS
$cshowList :: [Segment] -> ShowS
show :: Segment -> String
$cshow :: Segment -> String
showsPrec :: Int -> Segment -> ShowS
$cshowsPrec :: Int -> Segment -> ShowS
Prelude.Show, (forall x. Segment -> Rep Segment x)
-> (forall x. Rep Segment x -> Segment) -> Generic Segment
forall x. Rep Segment x -> Segment
forall x. Segment -> Rep Segment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Segment x -> Segment
$cfrom :: forall x. Segment -> Rep Segment x
Prelude.Generic)

-- |
-- Create a value of 'Segment' 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:
--
-- 'document', 'segment_document' - The segment document.
--
-- 'id', 'segment_id' - The segment\'s ID.
newSegment ::
  Segment
newSegment :: Segment
newSegment =
  Segment' :: Maybe Text -> Maybe Text -> Segment
Segment'
    { $sel:document:Segment' :: Maybe Text
document = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:id:Segment' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The segment document.
segment_document :: Lens.Lens' Segment (Prelude.Maybe Prelude.Text)
segment_document :: (Maybe Text -> f (Maybe Text)) -> Segment -> f Segment
segment_document = (Segment -> Maybe Text)
-> (Segment -> Maybe Text -> Segment)
-> Lens Segment Segment (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Maybe Text
document :: Maybe Text
$sel:document:Segment' :: Segment -> Maybe Text
document} -> Maybe Text
document) (\s :: Segment
s@Segment' {} Maybe Text
a -> Segment
s {$sel:document:Segment' :: Maybe Text
document = Maybe Text
a} :: Segment)

-- | The segment\'s ID.
segment_id :: Lens.Lens' Segment (Prelude.Maybe Prelude.Text)
segment_id :: (Maybe Text -> f (Maybe Text)) -> Segment -> f Segment
segment_id = (Segment -> Maybe Text)
-> (Segment -> Maybe Text -> Segment)
-> Lens Segment Segment (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Maybe Text
id :: Maybe Text
$sel:id:Segment' :: Segment -> Maybe Text
id} -> Maybe Text
id) (\s :: Segment
s@Segment' {} Maybe Text
a -> Segment
s {$sel:id:Segment' :: Maybe Text
id = Maybe Text
a} :: Segment)

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

instance Prelude.Hashable Segment

instance Prelude.NFData Segment