{-# 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.IoTSiteWise.Types.Resource
-- 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.IoTSiteWise.Types.Resource where

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.PortalResource
import Amazonka.IoTSiteWise.Types.ProjectResource
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains an IoT SiteWise Monitor resource ID for a portal or project.
--
-- /See:/ 'newResource' smart constructor.
data Resource = Resource'
  { -- | A portal resource.
    Resource -> Maybe PortalResource
portal :: Prelude.Maybe PortalResource,
    -- | A project resource.
    Resource -> Maybe ProjectResource
project :: Prelude.Maybe ProjectResource
  }
  deriving (Resource -> Resource -> Bool
(Resource -> Resource -> Bool)
-> (Resource -> Resource -> Bool) -> Eq Resource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Resource -> Resource -> Bool
$c/= :: Resource -> Resource -> Bool
== :: Resource -> Resource -> Bool
$c== :: Resource -> Resource -> Bool
Prelude.Eq, ReadPrec [Resource]
ReadPrec Resource
Int -> ReadS Resource
ReadS [Resource]
(Int -> ReadS Resource)
-> ReadS [Resource]
-> ReadPrec Resource
-> ReadPrec [Resource]
-> Read Resource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Resource]
$creadListPrec :: ReadPrec [Resource]
readPrec :: ReadPrec Resource
$creadPrec :: ReadPrec Resource
readList :: ReadS [Resource]
$creadList :: ReadS [Resource]
readsPrec :: Int -> ReadS Resource
$creadsPrec :: Int -> ReadS Resource
Prelude.Read, Int -> Resource -> ShowS
[Resource] -> ShowS
Resource -> String
(Int -> Resource -> ShowS)
-> (Resource -> String) -> ([Resource] -> ShowS) -> Show Resource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Resource] -> ShowS
$cshowList :: [Resource] -> ShowS
show :: Resource -> String
$cshow :: Resource -> String
showsPrec :: Int -> Resource -> ShowS
$cshowsPrec :: Int -> Resource -> ShowS
Prelude.Show, (forall x. Resource -> Rep Resource x)
-> (forall x. Rep Resource x -> Resource) -> Generic Resource
forall x. Rep Resource x -> Resource
forall x. Resource -> Rep Resource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Resource x -> Resource
$cfrom :: forall x. Resource -> Rep Resource x
Prelude.Generic)

-- |
-- Create a value of 'Resource' 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:
--
-- 'portal', 'resource_portal' - A portal resource.
--
-- 'project', 'resource_project' - A project resource.
newResource ::
  Resource
newResource :: Resource
newResource =
  Resource' :: Maybe PortalResource -> Maybe ProjectResource -> Resource
Resource'
    { $sel:portal:Resource' :: Maybe PortalResource
portal = Maybe PortalResource
forall a. Maybe a
Prelude.Nothing,
      $sel:project:Resource' :: Maybe ProjectResource
project = Maybe ProjectResource
forall a. Maybe a
Prelude.Nothing
    }

-- | A portal resource.
resource_portal :: Lens.Lens' Resource (Prelude.Maybe PortalResource)
resource_portal :: (Maybe PortalResource -> f (Maybe PortalResource))
-> Resource -> f Resource
resource_portal = (Resource -> Maybe PortalResource)
-> (Resource -> Maybe PortalResource -> Resource)
-> Lens
     Resource Resource (Maybe PortalResource) (Maybe PortalResource)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe PortalResource
portal :: Maybe PortalResource
$sel:portal:Resource' :: Resource -> Maybe PortalResource
portal} -> Maybe PortalResource
portal) (\s :: Resource
s@Resource' {} Maybe PortalResource
a -> Resource
s {$sel:portal:Resource' :: Maybe PortalResource
portal = Maybe PortalResource
a} :: Resource)

-- | A project resource.
resource_project :: Lens.Lens' Resource (Prelude.Maybe ProjectResource)
resource_project :: (Maybe ProjectResource -> f (Maybe ProjectResource))
-> Resource -> f Resource
resource_project = (Resource -> Maybe ProjectResource)
-> (Resource -> Maybe ProjectResource -> Resource)
-> Lens
     Resource Resource (Maybe ProjectResource) (Maybe ProjectResource)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe ProjectResource
project :: Maybe ProjectResource
$sel:project:Resource' :: Resource -> Maybe ProjectResource
project} -> Maybe ProjectResource
project) (\s :: Resource
s@Resource' {} Maybe ProjectResource
a -> Resource
s {$sel:project:Resource' :: Maybe ProjectResource
project = Maybe ProjectResource
a} :: Resource)

instance Core.FromJSON Resource where
  parseJSON :: Value -> Parser Resource
parseJSON =
    String -> (Object -> Parser Resource) -> Value -> Parser Resource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Resource"
      ( \Object
x ->
          Maybe PortalResource -> Maybe ProjectResource -> Resource
Resource'
            (Maybe PortalResource -> Maybe ProjectResource -> Resource)
-> Parser (Maybe PortalResource)
-> Parser (Maybe ProjectResource -> Resource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe PortalResource)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"portal")
            Parser (Maybe ProjectResource -> Resource)
-> Parser (Maybe ProjectResource) -> Parser Resource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ProjectResource)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"project")
      )

instance Prelude.Hashable Resource

instance Prelude.NFData Resource

instance Core.ToJSON Resource where
  toJSON :: Resource -> Value
toJSON Resource' {Maybe PortalResource
Maybe ProjectResource
project :: Maybe ProjectResource
portal :: Maybe PortalResource
$sel:project:Resource' :: Resource -> Maybe ProjectResource
$sel:portal:Resource' :: Resource -> Maybe PortalResource
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"portal" Text -> PortalResource -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (PortalResource -> Pair) -> Maybe PortalResource -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PortalResource
portal,
            (Text
"project" Text -> ProjectResource -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ProjectResource -> Pair) -> Maybe ProjectResource -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ProjectResource
project
          ]
      )