{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoTSiteWise.Types.Resource where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTSiteWise.Types.PortalResource
import Amazonka.IoTSiteWise.Types.ProjectResource
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
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]
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
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. 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'
    { $sel:portal:Resource' :: Maybe PortalResource
portal = forall a. Maybe a
Prelude.Nothing,
      $sel:project:Resource' :: Maybe ProjectResource
project = forall a. Maybe a
Prelude.Nothing
    }

-- | A portal resource.
resource_portal :: Lens.Lens' Resource (Prelude.Maybe PortalResource)
resource_portal :: Lens' Resource (Maybe PortalResource)
resource_portal = 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 :: Lens' Resource (Maybe ProjectResource)
resource_project = 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 Data.FromJSON Resource where
  parseJSON :: Value -> Parser Resource
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Resource"
      ( \Object
x ->
          Maybe PortalResource -> Maybe ProjectResource -> Resource
Resource'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"portal")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"project")
      )

instance Prelude.Hashable Resource where
  hashWithSalt :: Int -> Resource -> Int
hashWithSalt Int
_salt Resource' {Maybe PortalResource
Maybe ProjectResource
project :: Maybe ProjectResource
portal :: Maybe PortalResource
$sel:project:Resource' :: Resource -> Maybe ProjectResource
$sel:portal:Resource' :: Resource -> Maybe PortalResource
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PortalResource
portal
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ProjectResource
project

instance Prelude.NFData Resource where
  rnf :: Resource -> ()
rnf Resource' {Maybe PortalResource
Maybe ProjectResource
project :: Maybe ProjectResource
portal :: Maybe PortalResource
$sel:project:Resource' :: Resource -> Maybe ProjectResource
$sel:portal:Resource' :: Resource -> Maybe PortalResource
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe PortalResource
portal
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ProjectResource
project

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"portal" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PortalResource
portal,
            (Key
"project" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ProjectResource
project
          ]
      )