{-# 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.DataBrew.CreateSchedule
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a new schedule for one or more DataBrew jobs. Jobs can be run at
-- a specific date and time, or at regular intervals.
module Amazonka.DataBrew.CreateSchedule
  ( -- * Creating a Request
    CreateSchedule (..),
    newCreateSchedule,

    -- * Request Lenses
    createSchedule_jobNames,
    createSchedule_tags,
    createSchedule_cronExpression,
    createSchedule_name,

    -- * Destructuring the Response
    CreateScheduleResponse (..),
    newCreateScheduleResponse,

    -- * Response Lenses
    createScheduleResponse_httpStatus,
    createScheduleResponse_name,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DataBrew.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateSchedule' smart constructor.
data CreateSchedule = CreateSchedule'
  { -- | The name or names of one or more jobs to be run.
    CreateSchedule -> Maybe [Text]
jobNames :: Prelude.Maybe [Prelude.Text],
    -- | Metadata tags to apply to this schedule.
    CreateSchedule -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The date or dates and time or times when the jobs are to be run. For
    -- more information, see
    -- <https://docs.aws.amazon.com/databrew/latest/dg/jobs.cron.html Cron expressions>
    -- in the /Glue DataBrew Developer Guide/.
    CreateSchedule -> Text
cronExpression :: Prelude.Text,
    -- | A unique name for the schedule. Valid characters are alphanumeric (A-Z,
    -- a-z, 0-9), hyphen (-), period (.), and space.
    CreateSchedule -> Text
name :: Prelude.Text
  }
  deriving (CreateSchedule -> CreateSchedule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateSchedule -> CreateSchedule -> Bool
$c/= :: CreateSchedule -> CreateSchedule -> Bool
== :: CreateSchedule -> CreateSchedule -> Bool
$c== :: CreateSchedule -> CreateSchedule -> Bool
Prelude.Eq, ReadPrec [CreateSchedule]
ReadPrec CreateSchedule
Int -> ReadS CreateSchedule
ReadS [CreateSchedule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateSchedule]
$creadListPrec :: ReadPrec [CreateSchedule]
readPrec :: ReadPrec CreateSchedule
$creadPrec :: ReadPrec CreateSchedule
readList :: ReadS [CreateSchedule]
$creadList :: ReadS [CreateSchedule]
readsPrec :: Int -> ReadS CreateSchedule
$creadsPrec :: Int -> ReadS CreateSchedule
Prelude.Read, Int -> CreateSchedule -> ShowS
[CreateSchedule] -> ShowS
CreateSchedule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateSchedule] -> ShowS
$cshowList :: [CreateSchedule] -> ShowS
show :: CreateSchedule -> String
$cshow :: CreateSchedule -> String
showsPrec :: Int -> CreateSchedule -> ShowS
$cshowsPrec :: Int -> CreateSchedule -> ShowS
Prelude.Show, forall x. Rep CreateSchedule x -> CreateSchedule
forall x. CreateSchedule -> Rep CreateSchedule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateSchedule x -> CreateSchedule
$cfrom :: forall x. CreateSchedule -> Rep CreateSchedule x
Prelude.Generic)

-- |
-- Create a value of 'CreateSchedule' 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:
--
-- 'jobNames', 'createSchedule_jobNames' - The name or names of one or more jobs to be run.
--
-- 'tags', 'createSchedule_tags' - Metadata tags to apply to this schedule.
--
-- 'cronExpression', 'createSchedule_cronExpression' - The date or dates and time or times when the jobs are to be run. For
-- more information, see
-- <https://docs.aws.amazon.com/databrew/latest/dg/jobs.cron.html Cron expressions>
-- in the /Glue DataBrew Developer Guide/.
--
-- 'name', 'createSchedule_name' - A unique name for the schedule. Valid characters are alphanumeric (A-Z,
-- a-z, 0-9), hyphen (-), period (.), and space.
newCreateSchedule ::
  -- | 'cronExpression'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  CreateSchedule
newCreateSchedule :: Text -> Text -> CreateSchedule
newCreateSchedule Text
pCronExpression_ Text
pName_ =
  CreateSchedule'
    { $sel:jobNames:CreateSchedule' :: Maybe [Text]
jobNames = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateSchedule' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:cronExpression:CreateSchedule' :: Text
cronExpression = Text
pCronExpression_,
      $sel:name:CreateSchedule' :: Text
name = Text
pName_
    }

-- | The name or names of one or more jobs to be run.
createSchedule_jobNames :: Lens.Lens' CreateSchedule (Prelude.Maybe [Prelude.Text])
createSchedule_jobNames :: Lens' CreateSchedule (Maybe [Text])
createSchedule_jobNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSchedule' {Maybe [Text]
jobNames :: Maybe [Text]
$sel:jobNames:CreateSchedule' :: CreateSchedule -> Maybe [Text]
jobNames} -> Maybe [Text]
jobNames) (\s :: CreateSchedule
s@CreateSchedule' {} Maybe [Text]
a -> CreateSchedule
s {$sel:jobNames:CreateSchedule' :: Maybe [Text]
jobNames = Maybe [Text]
a} :: CreateSchedule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Metadata tags to apply to this schedule.
createSchedule_tags :: Lens.Lens' CreateSchedule (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createSchedule_tags :: Lens' CreateSchedule (Maybe (HashMap Text Text))
createSchedule_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSchedule' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateSchedule' :: CreateSchedule -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateSchedule
s@CreateSchedule' {} Maybe (HashMap Text Text)
a -> CreateSchedule
s {$sel:tags:CreateSchedule' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateSchedule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The date or dates and time or times when the jobs are to be run. For
-- more information, see
-- <https://docs.aws.amazon.com/databrew/latest/dg/jobs.cron.html Cron expressions>
-- in the /Glue DataBrew Developer Guide/.
createSchedule_cronExpression :: Lens.Lens' CreateSchedule Prelude.Text
createSchedule_cronExpression :: Lens' CreateSchedule Text
createSchedule_cronExpression = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSchedule' {Text
cronExpression :: Text
$sel:cronExpression:CreateSchedule' :: CreateSchedule -> Text
cronExpression} -> Text
cronExpression) (\s :: CreateSchedule
s@CreateSchedule' {} Text
a -> CreateSchedule
s {$sel:cronExpression:CreateSchedule' :: Text
cronExpression = Text
a} :: CreateSchedule)

-- | A unique name for the schedule. Valid characters are alphanumeric (A-Z,
-- a-z, 0-9), hyphen (-), period (.), and space.
createSchedule_name :: Lens.Lens' CreateSchedule Prelude.Text
createSchedule_name :: Lens' CreateSchedule Text
createSchedule_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSchedule' {Text
name :: Text
$sel:name:CreateSchedule' :: CreateSchedule -> Text
name} -> Text
name) (\s :: CreateSchedule
s@CreateSchedule' {} Text
a -> CreateSchedule
s {$sel:name:CreateSchedule' :: Text
name = Text
a} :: CreateSchedule)

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

instance Prelude.Hashable CreateSchedule where
  hashWithSalt :: Int -> CreateSchedule -> Int
hashWithSalt Int
_salt CreateSchedule' {Maybe [Text]
Maybe (HashMap Text Text)
Text
name :: Text
cronExpression :: Text
tags :: Maybe (HashMap Text Text)
jobNames :: Maybe [Text]
$sel:name:CreateSchedule' :: CreateSchedule -> Text
$sel:cronExpression:CreateSchedule' :: CreateSchedule -> Text
$sel:tags:CreateSchedule' :: CreateSchedule -> Maybe (HashMap Text Text)
$sel:jobNames:CreateSchedule' :: CreateSchedule -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
jobNames
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
cronExpression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData CreateSchedule where
  rnf :: CreateSchedule -> ()
rnf CreateSchedule' {Maybe [Text]
Maybe (HashMap Text Text)
Text
name :: Text
cronExpression :: Text
tags :: Maybe (HashMap Text Text)
jobNames :: Maybe [Text]
$sel:name:CreateSchedule' :: CreateSchedule -> Text
$sel:cronExpression:CreateSchedule' :: CreateSchedule -> Text
$sel:tags:CreateSchedule' :: CreateSchedule -> Maybe (HashMap Text Text)
$sel:jobNames:CreateSchedule' :: CreateSchedule -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
jobNames
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
cronExpression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name

instance Data.ToHeaders CreateSchedule where
  toHeaders :: CreateSchedule -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateSchedule where
  toJSON :: CreateSchedule -> Value
toJSON CreateSchedule' {Maybe [Text]
Maybe (HashMap Text Text)
Text
name :: Text
cronExpression :: Text
tags :: Maybe (HashMap Text Text)
jobNames :: Maybe [Text]
$sel:name:CreateSchedule' :: CreateSchedule -> Text
$sel:cronExpression:CreateSchedule' :: CreateSchedule -> Text
$sel:tags:CreateSchedule' :: CreateSchedule -> Maybe (HashMap Text Text)
$sel:jobNames:CreateSchedule' :: CreateSchedule -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"JobNames" 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 [Text]
jobNames,
            (Key
"Tags" 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 (HashMap Text Text)
tags,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"CronExpression" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
cronExpression),
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name)
          ]
      )

instance Data.ToPath CreateSchedule where
  toPath :: CreateSchedule -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/schedules"

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

-- | /See:/ 'newCreateScheduleResponse' smart constructor.
data CreateScheduleResponse = CreateScheduleResponse'
  { -- | The response's http status code.
    CreateScheduleResponse -> Int
httpStatus :: Prelude.Int,
    -- | The name of the schedule that was created.
    CreateScheduleResponse -> Text
name :: Prelude.Text
  }
  deriving (CreateScheduleResponse -> CreateScheduleResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateScheduleResponse -> CreateScheduleResponse -> Bool
$c/= :: CreateScheduleResponse -> CreateScheduleResponse -> Bool
== :: CreateScheduleResponse -> CreateScheduleResponse -> Bool
$c== :: CreateScheduleResponse -> CreateScheduleResponse -> Bool
Prelude.Eq, ReadPrec [CreateScheduleResponse]
ReadPrec CreateScheduleResponse
Int -> ReadS CreateScheduleResponse
ReadS [CreateScheduleResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateScheduleResponse]
$creadListPrec :: ReadPrec [CreateScheduleResponse]
readPrec :: ReadPrec CreateScheduleResponse
$creadPrec :: ReadPrec CreateScheduleResponse
readList :: ReadS [CreateScheduleResponse]
$creadList :: ReadS [CreateScheduleResponse]
readsPrec :: Int -> ReadS CreateScheduleResponse
$creadsPrec :: Int -> ReadS CreateScheduleResponse
Prelude.Read, Int -> CreateScheduleResponse -> ShowS
[CreateScheduleResponse] -> ShowS
CreateScheduleResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateScheduleResponse] -> ShowS
$cshowList :: [CreateScheduleResponse] -> ShowS
show :: CreateScheduleResponse -> String
$cshow :: CreateScheduleResponse -> String
showsPrec :: Int -> CreateScheduleResponse -> ShowS
$cshowsPrec :: Int -> CreateScheduleResponse -> ShowS
Prelude.Show, forall x. Rep CreateScheduleResponse x -> CreateScheduleResponse
forall x. CreateScheduleResponse -> Rep CreateScheduleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateScheduleResponse x -> CreateScheduleResponse
$cfrom :: forall x. CreateScheduleResponse -> Rep CreateScheduleResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateScheduleResponse' 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', 'createScheduleResponse_httpStatus' - The response's http status code.
--
-- 'name', 'createScheduleResponse_name' - The name of the schedule that was created.
newCreateScheduleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'name'
  Prelude.Text ->
  CreateScheduleResponse
newCreateScheduleResponse :: Int -> Text -> CreateScheduleResponse
newCreateScheduleResponse Int
pHttpStatus_ Text
pName_ =
  CreateScheduleResponse'
    { $sel:httpStatus:CreateScheduleResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:name:CreateScheduleResponse' :: Text
name = Text
pName_
    }

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

-- | The name of the schedule that was created.
createScheduleResponse_name :: Lens.Lens' CreateScheduleResponse Prelude.Text
createScheduleResponse_name :: Lens' CreateScheduleResponse Text
createScheduleResponse_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateScheduleResponse' {Text
name :: Text
$sel:name:CreateScheduleResponse' :: CreateScheduleResponse -> Text
name} -> Text
name) (\s :: CreateScheduleResponse
s@CreateScheduleResponse' {} Text
a -> CreateScheduleResponse
s {$sel:name:CreateScheduleResponse' :: Text
name = Text
a} :: CreateScheduleResponse)

instance Prelude.NFData CreateScheduleResponse where
  rnf :: CreateScheduleResponse -> ()
rnf CreateScheduleResponse' {Int
Text
name :: Text
httpStatus :: Int
$sel:name:CreateScheduleResponse' :: CreateScheduleResponse -> Text
$sel:httpStatus:CreateScheduleResponse' :: CreateScheduleResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name