{-# 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.MacieV2.GetFindings
-- 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)
--
-- Retrieves the details of one or more findings.
module Amazonka.MacieV2.GetFindings
  ( -- * Creating a Request
    GetFindings (..),
    newGetFindings,

    -- * Request Lenses
    getFindings_sortCriteria,
    getFindings_findingIds,

    -- * Destructuring the Response
    GetFindingsResponse (..),
    newGetFindingsResponse,

    -- * Response Lenses
    getFindingsResponse_findings,
    getFindingsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetFindings' smart constructor.
data GetFindings = GetFindings'
  { -- | The criteria for sorting the results of the request.
    GetFindings -> Maybe SortCriteria
sortCriteria :: Prelude.Maybe SortCriteria,
    -- | An array of strings that lists the unique identifiers for the findings
    -- to retrieve.
    GetFindings -> [Text]
findingIds :: [Prelude.Text]
  }
  deriving (GetFindings -> GetFindings -> Bool
(GetFindings -> GetFindings -> Bool)
-> (GetFindings -> GetFindings -> Bool) -> Eq GetFindings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetFindings -> GetFindings -> Bool
$c/= :: GetFindings -> GetFindings -> Bool
== :: GetFindings -> GetFindings -> Bool
$c== :: GetFindings -> GetFindings -> Bool
Prelude.Eq, ReadPrec [GetFindings]
ReadPrec GetFindings
Int -> ReadS GetFindings
ReadS [GetFindings]
(Int -> ReadS GetFindings)
-> ReadS [GetFindings]
-> ReadPrec GetFindings
-> ReadPrec [GetFindings]
-> Read GetFindings
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetFindings]
$creadListPrec :: ReadPrec [GetFindings]
readPrec :: ReadPrec GetFindings
$creadPrec :: ReadPrec GetFindings
readList :: ReadS [GetFindings]
$creadList :: ReadS [GetFindings]
readsPrec :: Int -> ReadS GetFindings
$creadsPrec :: Int -> ReadS GetFindings
Prelude.Read, Int -> GetFindings -> ShowS
[GetFindings] -> ShowS
GetFindings -> String
(Int -> GetFindings -> ShowS)
-> (GetFindings -> String)
-> ([GetFindings] -> ShowS)
-> Show GetFindings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetFindings] -> ShowS
$cshowList :: [GetFindings] -> ShowS
show :: GetFindings -> String
$cshow :: GetFindings -> String
showsPrec :: Int -> GetFindings -> ShowS
$cshowsPrec :: Int -> GetFindings -> ShowS
Prelude.Show, (forall x. GetFindings -> Rep GetFindings x)
-> (forall x. Rep GetFindings x -> GetFindings)
-> Generic GetFindings
forall x. Rep GetFindings x -> GetFindings
forall x. GetFindings -> Rep GetFindings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetFindings x -> GetFindings
$cfrom :: forall x. GetFindings -> Rep GetFindings x
Prelude.Generic)

-- |
-- Create a value of 'GetFindings' 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:
--
-- 'sortCriteria', 'getFindings_sortCriteria' - The criteria for sorting the results of the request.
--
-- 'findingIds', 'getFindings_findingIds' - An array of strings that lists the unique identifiers for the findings
-- to retrieve.
newGetFindings ::
  GetFindings
newGetFindings :: GetFindings
newGetFindings =
  GetFindings' :: Maybe SortCriteria -> [Text] -> GetFindings
GetFindings'
    { $sel:sortCriteria:GetFindings' :: Maybe SortCriteria
sortCriteria = Maybe SortCriteria
forall a. Maybe a
Prelude.Nothing,
      $sel:findingIds:GetFindings' :: [Text]
findingIds = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The criteria for sorting the results of the request.
getFindings_sortCriteria :: Lens.Lens' GetFindings (Prelude.Maybe SortCriteria)
getFindings_sortCriteria :: (Maybe SortCriteria -> f (Maybe SortCriteria))
-> GetFindings -> f GetFindings
getFindings_sortCriteria = (GetFindings -> Maybe SortCriteria)
-> (GetFindings -> Maybe SortCriteria -> GetFindings)
-> Lens
     GetFindings GetFindings (Maybe SortCriteria) (Maybe SortCriteria)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFindings' {Maybe SortCriteria
sortCriteria :: Maybe SortCriteria
$sel:sortCriteria:GetFindings' :: GetFindings -> Maybe SortCriteria
sortCriteria} -> Maybe SortCriteria
sortCriteria) (\s :: GetFindings
s@GetFindings' {} Maybe SortCriteria
a -> GetFindings
s {$sel:sortCriteria:GetFindings' :: Maybe SortCriteria
sortCriteria = Maybe SortCriteria
a} :: GetFindings)

-- | An array of strings that lists the unique identifiers for the findings
-- to retrieve.
getFindings_findingIds :: Lens.Lens' GetFindings [Prelude.Text]
getFindings_findingIds :: ([Text] -> f [Text]) -> GetFindings -> f GetFindings
getFindings_findingIds = (GetFindings -> [Text])
-> (GetFindings -> [Text] -> GetFindings)
-> Lens GetFindings GetFindings [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFindings' {[Text]
findingIds :: [Text]
$sel:findingIds:GetFindings' :: GetFindings -> [Text]
findingIds} -> [Text]
findingIds) (\s :: GetFindings
s@GetFindings' {} [Text]
a -> GetFindings
s {$sel:findingIds:GetFindings' :: [Text]
findingIds = [Text]
a} :: GetFindings) (([Text] -> f [Text]) -> GetFindings -> f GetFindings)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> GetFindings
-> f GetFindings
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest GetFindings where
  type AWSResponse GetFindings = GetFindingsResponse
  request :: GetFindings -> Request GetFindings
request = Service -> GetFindings -> Request GetFindings
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetFindings
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetFindings)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetFindings))
-> Logger
-> Service
-> Proxy GetFindings
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetFindings)))
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 ->
          Maybe [Finding] -> Int -> GetFindingsResponse
GetFindingsResponse'
            (Maybe [Finding] -> Int -> GetFindingsResponse)
-> Either String (Maybe [Finding])
-> Either String (Int -> GetFindingsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [Finding]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"findings" Either String (Maybe (Maybe [Finding]))
-> Maybe [Finding] -> Either String (Maybe [Finding])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Finding]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> GetFindingsResponse)
-> Either String Int -> Either String GetFindingsResponse
forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable GetFindings

instance Prelude.NFData GetFindings

instance Core.ToHeaders GetFindings where
  toHeaders :: GetFindings -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetFindings -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 GetFindings where
  toJSON :: GetFindings -> Value
toJSON GetFindings' {[Text]
Maybe SortCriteria
findingIds :: [Text]
sortCriteria :: Maybe SortCriteria
$sel:findingIds:GetFindings' :: GetFindings -> [Text]
$sel:sortCriteria:GetFindings' :: GetFindings -> Maybe SortCriteria
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"sortCriteria" Text -> SortCriteria -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SortCriteria -> Pair) -> Maybe SortCriteria -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SortCriteria
sortCriteria,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"findingIds" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
findingIds)
          ]
      )

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

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

-- | /See:/ 'newGetFindingsResponse' smart constructor.
data GetFindingsResponse = GetFindingsResponse'
  { -- | An array of objects, one for each finding that meets the criteria
    -- specified in the request.
    GetFindingsResponse -> Maybe [Finding]
findings :: Prelude.Maybe [Finding],
    -- | The response's http status code.
    GetFindingsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetFindingsResponse -> GetFindingsResponse -> Bool
(GetFindingsResponse -> GetFindingsResponse -> Bool)
-> (GetFindingsResponse -> GetFindingsResponse -> Bool)
-> Eq GetFindingsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetFindingsResponse -> GetFindingsResponse -> Bool
$c/= :: GetFindingsResponse -> GetFindingsResponse -> Bool
== :: GetFindingsResponse -> GetFindingsResponse -> Bool
$c== :: GetFindingsResponse -> GetFindingsResponse -> Bool
Prelude.Eq, ReadPrec [GetFindingsResponse]
ReadPrec GetFindingsResponse
Int -> ReadS GetFindingsResponse
ReadS [GetFindingsResponse]
(Int -> ReadS GetFindingsResponse)
-> ReadS [GetFindingsResponse]
-> ReadPrec GetFindingsResponse
-> ReadPrec [GetFindingsResponse]
-> Read GetFindingsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetFindingsResponse]
$creadListPrec :: ReadPrec [GetFindingsResponse]
readPrec :: ReadPrec GetFindingsResponse
$creadPrec :: ReadPrec GetFindingsResponse
readList :: ReadS [GetFindingsResponse]
$creadList :: ReadS [GetFindingsResponse]
readsPrec :: Int -> ReadS GetFindingsResponse
$creadsPrec :: Int -> ReadS GetFindingsResponse
Prelude.Read, Int -> GetFindingsResponse -> ShowS
[GetFindingsResponse] -> ShowS
GetFindingsResponse -> String
(Int -> GetFindingsResponse -> ShowS)
-> (GetFindingsResponse -> String)
-> ([GetFindingsResponse] -> ShowS)
-> Show GetFindingsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetFindingsResponse] -> ShowS
$cshowList :: [GetFindingsResponse] -> ShowS
show :: GetFindingsResponse -> String
$cshow :: GetFindingsResponse -> String
showsPrec :: Int -> GetFindingsResponse -> ShowS
$cshowsPrec :: Int -> GetFindingsResponse -> ShowS
Prelude.Show, (forall x. GetFindingsResponse -> Rep GetFindingsResponse x)
-> (forall x. Rep GetFindingsResponse x -> GetFindingsResponse)
-> Generic GetFindingsResponse
forall x. Rep GetFindingsResponse x -> GetFindingsResponse
forall x. GetFindingsResponse -> Rep GetFindingsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetFindingsResponse x -> GetFindingsResponse
$cfrom :: forall x. GetFindingsResponse -> Rep GetFindingsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetFindingsResponse' 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:
--
-- 'findings', 'getFindingsResponse_findings' - An array of objects, one for each finding that meets the criteria
-- specified in the request.
--
-- 'httpStatus', 'getFindingsResponse_httpStatus' - The response's http status code.
newGetFindingsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetFindingsResponse
newGetFindingsResponse :: Int -> GetFindingsResponse
newGetFindingsResponse Int
pHttpStatus_ =
  GetFindingsResponse' :: Maybe [Finding] -> Int -> GetFindingsResponse
GetFindingsResponse'
    { $sel:findings:GetFindingsResponse' :: Maybe [Finding]
findings = Maybe [Finding]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetFindingsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects, one for each finding that meets the criteria
-- specified in the request.
getFindingsResponse_findings :: Lens.Lens' GetFindingsResponse (Prelude.Maybe [Finding])
getFindingsResponse_findings :: (Maybe [Finding] -> f (Maybe [Finding]))
-> GetFindingsResponse -> f GetFindingsResponse
getFindingsResponse_findings = (GetFindingsResponse -> Maybe [Finding])
-> (GetFindingsResponse -> Maybe [Finding] -> GetFindingsResponse)
-> Lens
     GetFindingsResponse
     GetFindingsResponse
     (Maybe [Finding])
     (Maybe [Finding])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFindingsResponse' {Maybe [Finding]
findings :: Maybe [Finding]
$sel:findings:GetFindingsResponse' :: GetFindingsResponse -> Maybe [Finding]
findings} -> Maybe [Finding]
findings) (\s :: GetFindingsResponse
s@GetFindingsResponse' {} Maybe [Finding]
a -> GetFindingsResponse
s {$sel:findings:GetFindingsResponse' :: Maybe [Finding]
findings = Maybe [Finding]
a} :: GetFindingsResponse) ((Maybe [Finding] -> f (Maybe [Finding]))
 -> GetFindingsResponse -> f GetFindingsResponse)
-> ((Maybe [Finding] -> f (Maybe [Finding]))
    -> Maybe [Finding] -> f (Maybe [Finding]))
-> (Maybe [Finding] -> f (Maybe [Finding]))
-> GetFindingsResponse
-> f GetFindingsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Finding] [Finding] [Finding] [Finding]
-> Iso
     (Maybe [Finding])
     (Maybe [Finding])
     (Maybe [Finding])
     (Maybe [Finding])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Finding] [Finding] [Finding] [Finding]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetFindingsResponse