{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CostExplorer.CreateAnomalyMonitor
-- 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)
--
-- Creates a new cost anomaly detection monitor with the requested type and
-- monitor specification.
module Amazonka.CostExplorer.CreateAnomalyMonitor
  ( -- * Creating a Request
    CreateAnomalyMonitor (..),
    newCreateAnomalyMonitor,

    -- * Request Lenses
    createAnomalyMonitor_anomalyMonitor,

    -- * Destructuring the Response
    CreateAnomalyMonitorResponse (..),
    newCreateAnomalyMonitorResponse,

    -- * Response Lenses
    createAnomalyMonitorResponse_httpStatus,
    createAnomalyMonitorResponse_monitorArn,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.CostExplorer.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateAnomalyMonitor' smart constructor.
data CreateAnomalyMonitor = CreateAnomalyMonitor'
  { -- | The cost anomaly detection monitor object that you want to create.
    CreateAnomalyMonitor -> AnomalyMonitor
anomalyMonitor :: AnomalyMonitor
  }
  deriving (CreateAnomalyMonitor -> CreateAnomalyMonitor -> Bool
(CreateAnomalyMonitor -> CreateAnomalyMonitor -> Bool)
-> (CreateAnomalyMonitor -> CreateAnomalyMonitor -> Bool)
-> Eq CreateAnomalyMonitor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateAnomalyMonitor -> CreateAnomalyMonitor -> Bool
$c/= :: CreateAnomalyMonitor -> CreateAnomalyMonitor -> Bool
== :: CreateAnomalyMonitor -> CreateAnomalyMonitor -> Bool
$c== :: CreateAnomalyMonitor -> CreateAnomalyMonitor -> Bool
Prelude.Eq, ReadPrec [CreateAnomalyMonitor]
ReadPrec CreateAnomalyMonitor
Int -> ReadS CreateAnomalyMonitor
ReadS [CreateAnomalyMonitor]
(Int -> ReadS CreateAnomalyMonitor)
-> ReadS [CreateAnomalyMonitor]
-> ReadPrec CreateAnomalyMonitor
-> ReadPrec [CreateAnomalyMonitor]
-> Read CreateAnomalyMonitor
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateAnomalyMonitor]
$creadListPrec :: ReadPrec [CreateAnomalyMonitor]
readPrec :: ReadPrec CreateAnomalyMonitor
$creadPrec :: ReadPrec CreateAnomalyMonitor
readList :: ReadS [CreateAnomalyMonitor]
$creadList :: ReadS [CreateAnomalyMonitor]
readsPrec :: Int -> ReadS CreateAnomalyMonitor
$creadsPrec :: Int -> ReadS CreateAnomalyMonitor
Prelude.Read, Int -> CreateAnomalyMonitor -> ShowS
[CreateAnomalyMonitor] -> ShowS
CreateAnomalyMonitor -> String
(Int -> CreateAnomalyMonitor -> ShowS)
-> (CreateAnomalyMonitor -> String)
-> ([CreateAnomalyMonitor] -> ShowS)
-> Show CreateAnomalyMonitor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateAnomalyMonitor] -> ShowS
$cshowList :: [CreateAnomalyMonitor] -> ShowS
show :: CreateAnomalyMonitor -> String
$cshow :: CreateAnomalyMonitor -> String
showsPrec :: Int -> CreateAnomalyMonitor -> ShowS
$cshowsPrec :: Int -> CreateAnomalyMonitor -> ShowS
Prelude.Show, (forall x. CreateAnomalyMonitor -> Rep CreateAnomalyMonitor x)
-> (forall x. Rep CreateAnomalyMonitor x -> CreateAnomalyMonitor)
-> Generic CreateAnomalyMonitor
forall x. Rep CreateAnomalyMonitor x -> CreateAnomalyMonitor
forall x. CreateAnomalyMonitor -> Rep CreateAnomalyMonitor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateAnomalyMonitor x -> CreateAnomalyMonitor
$cfrom :: forall x. CreateAnomalyMonitor -> Rep CreateAnomalyMonitor x
Prelude.Generic)

-- |
-- Create a value of 'CreateAnomalyMonitor' 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:
--
-- 'anomalyMonitor', 'createAnomalyMonitor_anomalyMonitor' - The cost anomaly detection monitor object that you want to create.
newCreateAnomalyMonitor ::
  -- | 'anomalyMonitor'
  AnomalyMonitor ->
  CreateAnomalyMonitor
newCreateAnomalyMonitor :: AnomalyMonitor -> CreateAnomalyMonitor
newCreateAnomalyMonitor AnomalyMonitor
pAnomalyMonitor_ =
  CreateAnomalyMonitor' :: AnomalyMonitor -> CreateAnomalyMonitor
CreateAnomalyMonitor'
    { $sel:anomalyMonitor:CreateAnomalyMonitor' :: AnomalyMonitor
anomalyMonitor =
        AnomalyMonitor
pAnomalyMonitor_
    }

-- | The cost anomaly detection monitor object that you want to create.
createAnomalyMonitor_anomalyMonitor :: Lens.Lens' CreateAnomalyMonitor AnomalyMonitor
createAnomalyMonitor_anomalyMonitor :: (AnomalyMonitor -> f AnomalyMonitor)
-> CreateAnomalyMonitor -> f CreateAnomalyMonitor
createAnomalyMonitor_anomalyMonitor = (CreateAnomalyMonitor -> AnomalyMonitor)
-> (CreateAnomalyMonitor -> AnomalyMonitor -> CreateAnomalyMonitor)
-> Lens
     CreateAnomalyMonitor
     CreateAnomalyMonitor
     AnomalyMonitor
     AnomalyMonitor
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAnomalyMonitor' {AnomalyMonitor
anomalyMonitor :: AnomalyMonitor
$sel:anomalyMonitor:CreateAnomalyMonitor' :: CreateAnomalyMonitor -> AnomalyMonitor
anomalyMonitor} -> AnomalyMonitor
anomalyMonitor) (\s :: CreateAnomalyMonitor
s@CreateAnomalyMonitor' {} AnomalyMonitor
a -> CreateAnomalyMonitor
s {$sel:anomalyMonitor:CreateAnomalyMonitor' :: AnomalyMonitor
anomalyMonitor = AnomalyMonitor
a} :: CreateAnomalyMonitor)

instance Core.AWSRequest CreateAnomalyMonitor where
  type
    AWSResponse CreateAnomalyMonitor =
      CreateAnomalyMonitorResponse
  request :: CreateAnomalyMonitor -> Request CreateAnomalyMonitor
request = Service -> CreateAnomalyMonitor -> Request CreateAnomalyMonitor
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateAnomalyMonitor
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateAnomalyMonitor)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateAnomalyMonitor))
-> Logger
-> Service
-> Proxy CreateAnomalyMonitor
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateAnomalyMonitor)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> CreateAnomalyMonitorResponse
CreateAnomalyMonitorResponse'
            (Int -> Text -> CreateAnomalyMonitorResponse)
-> Either String Int
-> Either String (Text -> CreateAnomalyMonitorResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String (Text -> CreateAnomalyMonitorResponse)
-> Either String Text -> Either String CreateAnomalyMonitorResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Text
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"MonitorArn")
      )

instance Prelude.Hashable CreateAnomalyMonitor

instance Prelude.NFData CreateAnomalyMonitor

instance Core.ToHeaders CreateAnomalyMonitor where
  toHeaders :: CreateAnomalyMonitor -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateAnomalyMonitor -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSInsightsIndexService.CreateAnomalyMonitor" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateAnomalyMonitor where
  toJSON :: CreateAnomalyMonitor -> Value
toJSON CreateAnomalyMonitor' {AnomalyMonitor
anomalyMonitor :: AnomalyMonitor
$sel:anomalyMonitor:CreateAnomalyMonitor' :: CreateAnomalyMonitor -> AnomalyMonitor
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"AnomalyMonitor" Text -> AnomalyMonitor -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AnomalyMonitor
anomalyMonitor)
          ]
      )

instance Core.ToPath CreateAnomalyMonitor where
  toPath :: CreateAnomalyMonitor -> ByteString
toPath = ByteString -> CreateAnomalyMonitor -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery CreateAnomalyMonitor where
  toQuery :: CreateAnomalyMonitor -> QueryString
toQuery = QueryString -> CreateAnomalyMonitor -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateAnomalyMonitorResponse' smart constructor.
data CreateAnomalyMonitorResponse = CreateAnomalyMonitorResponse'
  { -- | The response's http status code.
    CreateAnomalyMonitorResponse -> Int
httpStatus :: Prelude.Int,
    -- | The unique identifier of your newly created cost anomaly detection
    -- monitor.
    CreateAnomalyMonitorResponse -> Text
monitorArn :: Prelude.Text
  }
  deriving (CreateAnomalyMonitorResponse
-> CreateAnomalyMonitorResponse -> Bool
(CreateAnomalyMonitorResponse
 -> CreateAnomalyMonitorResponse -> Bool)
-> (CreateAnomalyMonitorResponse
    -> CreateAnomalyMonitorResponse -> Bool)
-> Eq CreateAnomalyMonitorResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateAnomalyMonitorResponse
-> CreateAnomalyMonitorResponse -> Bool
$c/= :: CreateAnomalyMonitorResponse
-> CreateAnomalyMonitorResponse -> Bool
== :: CreateAnomalyMonitorResponse
-> CreateAnomalyMonitorResponse -> Bool
$c== :: CreateAnomalyMonitorResponse
-> CreateAnomalyMonitorResponse -> Bool
Prelude.Eq, ReadPrec [CreateAnomalyMonitorResponse]
ReadPrec CreateAnomalyMonitorResponse
Int -> ReadS CreateAnomalyMonitorResponse
ReadS [CreateAnomalyMonitorResponse]
(Int -> ReadS CreateAnomalyMonitorResponse)
-> ReadS [CreateAnomalyMonitorResponse]
-> ReadPrec CreateAnomalyMonitorResponse
-> ReadPrec [CreateAnomalyMonitorResponse]
-> Read CreateAnomalyMonitorResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateAnomalyMonitorResponse]
$creadListPrec :: ReadPrec [CreateAnomalyMonitorResponse]
readPrec :: ReadPrec CreateAnomalyMonitorResponse
$creadPrec :: ReadPrec CreateAnomalyMonitorResponse
readList :: ReadS [CreateAnomalyMonitorResponse]
$creadList :: ReadS [CreateAnomalyMonitorResponse]
readsPrec :: Int -> ReadS CreateAnomalyMonitorResponse
$creadsPrec :: Int -> ReadS CreateAnomalyMonitorResponse
Prelude.Read, Int -> CreateAnomalyMonitorResponse -> ShowS
[CreateAnomalyMonitorResponse] -> ShowS
CreateAnomalyMonitorResponse -> String
(Int -> CreateAnomalyMonitorResponse -> ShowS)
-> (CreateAnomalyMonitorResponse -> String)
-> ([CreateAnomalyMonitorResponse] -> ShowS)
-> Show CreateAnomalyMonitorResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateAnomalyMonitorResponse] -> ShowS
$cshowList :: [CreateAnomalyMonitorResponse] -> ShowS
show :: CreateAnomalyMonitorResponse -> String
$cshow :: CreateAnomalyMonitorResponse -> String
showsPrec :: Int -> CreateAnomalyMonitorResponse -> ShowS
$cshowsPrec :: Int -> CreateAnomalyMonitorResponse -> ShowS
Prelude.Show, (forall x.
 CreateAnomalyMonitorResponse -> Rep CreateAnomalyMonitorResponse x)
-> (forall x.
    Rep CreateAnomalyMonitorResponse x -> CreateAnomalyMonitorResponse)
-> Generic CreateAnomalyMonitorResponse
forall x.
Rep CreateAnomalyMonitorResponse x -> CreateAnomalyMonitorResponse
forall x.
CreateAnomalyMonitorResponse -> Rep CreateAnomalyMonitorResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateAnomalyMonitorResponse x -> CreateAnomalyMonitorResponse
$cfrom :: forall x.
CreateAnomalyMonitorResponse -> Rep CreateAnomalyMonitorResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateAnomalyMonitorResponse' 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:
--
-- 'httpStatus', 'createAnomalyMonitorResponse_httpStatus' - The response's http status code.
--
-- 'monitorArn', 'createAnomalyMonitorResponse_monitorArn' - The unique identifier of your newly created cost anomaly detection
-- monitor.
newCreateAnomalyMonitorResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'monitorArn'
  Prelude.Text ->
  CreateAnomalyMonitorResponse
newCreateAnomalyMonitorResponse :: Int -> Text -> CreateAnomalyMonitorResponse
newCreateAnomalyMonitorResponse
  Int
pHttpStatus_
  Text
pMonitorArn_ =
    CreateAnomalyMonitorResponse' :: Int -> Text -> CreateAnomalyMonitorResponse
CreateAnomalyMonitorResponse'
      { $sel:httpStatus:CreateAnomalyMonitorResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:monitorArn:CreateAnomalyMonitorResponse' :: Text
monitorArn = Text
pMonitorArn_
      }

-- | The response's http status code.
createAnomalyMonitorResponse_httpStatus :: Lens.Lens' CreateAnomalyMonitorResponse Prelude.Int
createAnomalyMonitorResponse_httpStatus :: (Int -> f Int)
-> CreateAnomalyMonitorResponse -> f CreateAnomalyMonitorResponse
createAnomalyMonitorResponse_httpStatus = (CreateAnomalyMonitorResponse -> Int)
-> (CreateAnomalyMonitorResponse
    -> Int -> CreateAnomalyMonitorResponse)
-> Lens
     CreateAnomalyMonitorResponse CreateAnomalyMonitorResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAnomalyMonitorResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateAnomalyMonitorResponse' :: CreateAnomalyMonitorResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateAnomalyMonitorResponse
s@CreateAnomalyMonitorResponse' {} Int
a -> CreateAnomalyMonitorResponse
s {$sel:httpStatus:CreateAnomalyMonitorResponse' :: Int
httpStatus = Int
a} :: CreateAnomalyMonitorResponse)

-- | The unique identifier of your newly created cost anomaly detection
-- monitor.
createAnomalyMonitorResponse_monitorArn :: Lens.Lens' CreateAnomalyMonitorResponse Prelude.Text
createAnomalyMonitorResponse_monitorArn :: (Text -> f Text)
-> CreateAnomalyMonitorResponse -> f CreateAnomalyMonitorResponse
createAnomalyMonitorResponse_monitorArn = (CreateAnomalyMonitorResponse -> Text)
-> (CreateAnomalyMonitorResponse
    -> Text -> CreateAnomalyMonitorResponse)
-> Lens
     CreateAnomalyMonitorResponse CreateAnomalyMonitorResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAnomalyMonitorResponse' {Text
monitorArn :: Text
$sel:monitorArn:CreateAnomalyMonitorResponse' :: CreateAnomalyMonitorResponse -> Text
monitorArn} -> Text
monitorArn) (\s :: CreateAnomalyMonitorResponse
s@CreateAnomalyMonitorResponse' {} Text
a -> CreateAnomalyMonitorResponse
s {$sel:monitorArn:CreateAnomalyMonitorResponse' :: Text
monitorArn = Text
a} :: CreateAnomalyMonitorResponse)

instance Prelude.NFData CreateAnomalyMonitorResponse