{-# 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.CloudSearch.DescribeDomains
-- 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)
--
-- Gets information about the search domains owned by this account. Can be
-- limited to specific domains. Shows all domains by default. To get the
-- number of searchable documents in a domain, use the console or submit a
-- @matchall@ request to your domain\'s search endpoint:
-- @q=matchall&amp;q.parser=structured&amp;size=0@. For more information,
-- see
-- <http://docs.aws.amazon.com/cloudsearch/latest/developerguide/getting-domain-info.html Getting Information about a Search Domain>
-- in the /Amazon CloudSearch Developer Guide/.
module Amazonka.CloudSearch.DescribeDomains
  ( -- * Creating a Request
    DescribeDomains (..),
    newDescribeDomains,

    -- * Request Lenses
    describeDomains_domainNames,

    -- * Destructuring the Response
    DescribeDomainsResponse (..),
    newDescribeDomainsResponse,

    -- * Response Lenses
    describeDomainsResponse_httpStatus,
    describeDomainsResponse_domainStatusList,
  )
where

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

-- | Container for the parameters to the @DescribeDomains@ operation. By
-- default shows the status of all domains. To restrict the response to
-- particular domains, specify the names of the domains you want to
-- describe.
--
-- /See:/ 'newDescribeDomains' smart constructor.
data DescribeDomains = DescribeDomains'
  { -- | The names of the domains you want to include in the response.
    DescribeDomains -> Maybe [Text]
domainNames :: Prelude.Maybe [Prelude.Text]
  }
  deriving (DescribeDomains -> DescribeDomains -> Bool
(DescribeDomains -> DescribeDomains -> Bool)
-> (DescribeDomains -> DescribeDomains -> Bool)
-> Eq DescribeDomains
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeDomains -> DescribeDomains -> Bool
$c/= :: DescribeDomains -> DescribeDomains -> Bool
== :: DescribeDomains -> DescribeDomains -> Bool
$c== :: DescribeDomains -> DescribeDomains -> Bool
Prelude.Eq, ReadPrec [DescribeDomains]
ReadPrec DescribeDomains
Int -> ReadS DescribeDomains
ReadS [DescribeDomains]
(Int -> ReadS DescribeDomains)
-> ReadS [DescribeDomains]
-> ReadPrec DescribeDomains
-> ReadPrec [DescribeDomains]
-> Read DescribeDomains
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeDomains]
$creadListPrec :: ReadPrec [DescribeDomains]
readPrec :: ReadPrec DescribeDomains
$creadPrec :: ReadPrec DescribeDomains
readList :: ReadS [DescribeDomains]
$creadList :: ReadS [DescribeDomains]
readsPrec :: Int -> ReadS DescribeDomains
$creadsPrec :: Int -> ReadS DescribeDomains
Prelude.Read, Int -> DescribeDomains -> ShowS
[DescribeDomains] -> ShowS
DescribeDomains -> String
(Int -> DescribeDomains -> ShowS)
-> (DescribeDomains -> String)
-> ([DescribeDomains] -> ShowS)
-> Show DescribeDomains
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeDomains] -> ShowS
$cshowList :: [DescribeDomains] -> ShowS
show :: DescribeDomains -> String
$cshow :: DescribeDomains -> String
showsPrec :: Int -> DescribeDomains -> ShowS
$cshowsPrec :: Int -> DescribeDomains -> ShowS
Prelude.Show, (forall x. DescribeDomains -> Rep DescribeDomains x)
-> (forall x. Rep DescribeDomains x -> DescribeDomains)
-> Generic DescribeDomains
forall x. Rep DescribeDomains x -> DescribeDomains
forall x. DescribeDomains -> Rep DescribeDomains x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeDomains x -> DescribeDomains
$cfrom :: forall x. DescribeDomains -> Rep DescribeDomains x
Prelude.Generic)

-- |
-- Create a value of 'DescribeDomains' 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:
--
-- 'domainNames', 'describeDomains_domainNames' - The names of the domains you want to include in the response.
newDescribeDomains ::
  DescribeDomains
newDescribeDomains :: DescribeDomains
newDescribeDomains =
  DescribeDomains' :: Maybe [Text] -> DescribeDomains
DescribeDomains' {$sel:domainNames:DescribeDomains' :: Maybe [Text]
domainNames = Maybe [Text]
forall a. Maybe a
Prelude.Nothing}

-- | The names of the domains you want to include in the response.
describeDomains_domainNames :: Lens.Lens' DescribeDomains (Prelude.Maybe [Prelude.Text])
describeDomains_domainNames :: (Maybe [Text] -> f (Maybe [Text]))
-> DescribeDomains -> f DescribeDomains
describeDomains_domainNames = (DescribeDomains -> Maybe [Text])
-> (DescribeDomains -> Maybe [Text] -> DescribeDomains)
-> Lens
     DescribeDomains DescribeDomains (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeDomains' {Maybe [Text]
domainNames :: Maybe [Text]
$sel:domainNames:DescribeDomains' :: DescribeDomains -> Maybe [Text]
domainNames} -> Maybe [Text]
domainNames) (\s :: DescribeDomains
s@DescribeDomains' {} Maybe [Text]
a -> DescribeDomains
s {$sel:domainNames:DescribeDomains' :: Maybe [Text]
domainNames = Maybe [Text]
a} :: DescribeDomains) ((Maybe [Text] -> f (Maybe [Text]))
 -> DescribeDomains -> f DescribeDomains)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> DescribeDomains
-> f DescribeDomains
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest DescribeDomains where
  type
    AWSResponse DescribeDomains =
      DescribeDomainsResponse
  request :: DescribeDomains -> Request DescribeDomains
request = Service -> DescribeDomains -> Request DescribeDomains
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeDomains
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeDomains)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse DescribeDomains))
-> Logger
-> Service
-> Proxy DescribeDomains
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeDomains)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"DescribeDomainsResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> [DomainStatus] -> DescribeDomainsResponse
DescribeDomainsResponse'
            (Int -> [DomainStatus] -> DescribeDomainsResponse)
-> Either String Int
-> Either String ([DomainStatus] -> DescribeDomainsResponse)
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 ([DomainStatus] -> DescribeDomainsResponse)
-> Either String [DomainStatus]
-> Either String DescribeDomainsResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"DomainStatusList"
                            Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                            Either String [Node]
-> ([Node] -> Either String [DomainStatus])
-> Either String [DomainStatus]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String [DomainStatus]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member"
                        )
      )

instance Prelude.Hashable DescribeDomains

instance Prelude.NFData DescribeDomains

instance Core.ToHeaders DescribeDomains where
  toHeaders :: DescribeDomains -> ResponseHeaders
toHeaders = ResponseHeaders -> DescribeDomains -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery DescribeDomains where
  toQuery :: DescribeDomains -> QueryString
toQuery DescribeDomains' {Maybe [Text]
domainNames :: Maybe [Text]
$sel:domainNames:DescribeDomains' :: DescribeDomains -> Maybe [Text]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"DescribeDomains" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2013-01-01" :: Prelude.ByteString),
        ByteString
"DomainNames"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> [Text] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" ([Text] -> QueryString) -> Maybe [Text] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
domainNames)
      ]

-- | The result of a @DescribeDomains@ request. Contains the status of the
-- domains specified in the request or all domains owned by the account.
--
-- /See:/ 'newDescribeDomainsResponse' smart constructor.
data DescribeDomainsResponse = DescribeDomainsResponse'
  { -- | The response's http status code.
    DescribeDomainsResponse -> Int
httpStatus :: Prelude.Int,
    DescribeDomainsResponse -> [DomainStatus]
domainStatusList :: [DomainStatus]
  }
  deriving (DescribeDomainsResponse -> DescribeDomainsResponse -> Bool
(DescribeDomainsResponse -> DescribeDomainsResponse -> Bool)
-> (DescribeDomainsResponse -> DescribeDomainsResponse -> Bool)
-> Eq DescribeDomainsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeDomainsResponse -> DescribeDomainsResponse -> Bool
$c/= :: DescribeDomainsResponse -> DescribeDomainsResponse -> Bool
== :: DescribeDomainsResponse -> DescribeDomainsResponse -> Bool
$c== :: DescribeDomainsResponse -> DescribeDomainsResponse -> Bool
Prelude.Eq, ReadPrec [DescribeDomainsResponse]
ReadPrec DescribeDomainsResponse
Int -> ReadS DescribeDomainsResponse
ReadS [DescribeDomainsResponse]
(Int -> ReadS DescribeDomainsResponse)
-> ReadS [DescribeDomainsResponse]
-> ReadPrec DescribeDomainsResponse
-> ReadPrec [DescribeDomainsResponse]
-> Read DescribeDomainsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeDomainsResponse]
$creadListPrec :: ReadPrec [DescribeDomainsResponse]
readPrec :: ReadPrec DescribeDomainsResponse
$creadPrec :: ReadPrec DescribeDomainsResponse
readList :: ReadS [DescribeDomainsResponse]
$creadList :: ReadS [DescribeDomainsResponse]
readsPrec :: Int -> ReadS DescribeDomainsResponse
$creadsPrec :: Int -> ReadS DescribeDomainsResponse
Prelude.Read, Int -> DescribeDomainsResponse -> ShowS
[DescribeDomainsResponse] -> ShowS
DescribeDomainsResponse -> String
(Int -> DescribeDomainsResponse -> ShowS)
-> (DescribeDomainsResponse -> String)
-> ([DescribeDomainsResponse] -> ShowS)
-> Show DescribeDomainsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeDomainsResponse] -> ShowS
$cshowList :: [DescribeDomainsResponse] -> ShowS
show :: DescribeDomainsResponse -> String
$cshow :: DescribeDomainsResponse -> String
showsPrec :: Int -> DescribeDomainsResponse -> ShowS
$cshowsPrec :: Int -> DescribeDomainsResponse -> ShowS
Prelude.Show, (forall x.
 DescribeDomainsResponse -> Rep DescribeDomainsResponse x)
-> (forall x.
    Rep DescribeDomainsResponse x -> DescribeDomainsResponse)
-> Generic DescribeDomainsResponse
forall x. Rep DescribeDomainsResponse x -> DescribeDomainsResponse
forall x. DescribeDomainsResponse -> Rep DescribeDomainsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeDomainsResponse x -> DescribeDomainsResponse
$cfrom :: forall x. DescribeDomainsResponse -> Rep DescribeDomainsResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeDomainsResponse' 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', 'describeDomainsResponse_httpStatus' - The response's http status code.
--
-- 'domainStatusList', 'describeDomainsResponse_domainStatusList' - Undocumented member.
newDescribeDomainsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeDomainsResponse
newDescribeDomainsResponse :: Int -> DescribeDomainsResponse
newDescribeDomainsResponse Int
pHttpStatus_ =
  DescribeDomainsResponse' :: Int -> [DomainStatus] -> DescribeDomainsResponse
DescribeDomainsResponse'
    { $sel:httpStatus:DescribeDomainsResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:domainStatusList:DescribeDomainsResponse' :: [DomainStatus]
domainStatusList = [DomainStatus]
forall a. Monoid a => a
Prelude.mempty
    }

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

-- | Undocumented member.
describeDomainsResponse_domainStatusList :: Lens.Lens' DescribeDomainsResponse [DomainStatus]
describeDomainsResponse_domainStatusList :: ([DomainStatus] -> f [DomainStatus])
-> DescribeDomainsResponse -> f DescribeDomainsResponse
describeDomainsResponse_domainStatusList = (DescribeDomainsResponse -> [DomainStatus])
-> (DescribeDomainsResponse
    -> [DomainStatus] -> DescribeDomainsResponse)
-> Lens
     DescribeDomainsResponse
     DescribeDomainsResponse
     [DomainStatus]
     [DomainStatus]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeDomainsResponse' {[DomainStatus]
domainStatusList :: [DomainStatus]
$sel:domainStatusList:DescribeDomainsResponse' :: DescribeDomainsResponse -> [DomainStatus]
domainStatusList} -> [DomainStatus]
domainStatusList) (\s :: DescribeDomainsResponse
s@DescribeDomainsResponse' {} [DomainStatus]
a -> DescribeDomainsResponse
s {$sel:domainStatusList:DescribeDomainsResponse' :: [DomainStatus]
domainStatusList = [DomainStatus]
a} :: DescribeDomainsResponse) (([DomainStatus] -> f [DomainStatus])
 -> DescribeDomainsResponse -> f DescribeDomainsResponse)
-> (([DomainStatus] -> f [DomainStatus])
    -> [DomainStatus] -> f [DomainStatus])
-> ([DomainStatus] -> f [DomainStatus])
-> DescribeDomainsResponse
-> f DescribeDomainsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([DomainStatus] -> f [DomainStatus])
-> [DomainStatus] -> f [DomainStatus]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData DescribeDomainsResponse