module Network.PagerDuty.REST.MaintenanceWindows
(
ListWindows
, listWindows
, lwQuery
, lwServiceIds
, lwFilter
, ListWindowsResponse
, lwMaintenanceWindows
, lwCounts
, CreateWindow
, createWindow
, createWindowBasic
, cwStartTime
, cwEndTime
, cwDescription
, cwServiceIds
, getWindow
, UpdateWindow
, updateWindow
, uwStartTime
, uwEndTime
, uwDescription
, uwServiceIds
, deleteWindow
, ServiceInfo
, siId
, siName
, siUrl
, Counts
, cOngoing
, cFuture
, cPast
, cAll
, MaintenanceWindow
, mwSequenceNumber
, mwStartTime
, mwEndTime
, mwDescription
, mwCreatedBy
, mwServices
) where
import Control.Lens hiding (Empty)
import Data.Monoid
import Data.Text (Text)
import Data.Time
import Network.HTTP.Types
import Network.PagerDuty.Internal.TH
import Network.PagerDuty.Internal.Types
import Network.PagerDuty.REST.Users (User)
windows :: Path
windows = "maintenance_windows"
data ServiceInfo = ServiceInfo
{ _siId :: ServiceId
, _siName :: Text
, _siUrl :: Text
} deriving (Eq, Show)
deriveRecord ''ServiceInfo
data MaintenanceWindow = MaintenanceWindow
{ _mwSequenceNumber :: !Int
, _mwStartTime :: Date
, _mwEndTime :: Date
, _mwDescription :: Maybe Text
, _mwCreatedBy :: User
, _mwServices :: [ServiceInfo]
} deriving (Eq, Show)
deriveRecord ''MaintenanceWindow
data ListWindows = ListWindows
{ _lwQuery' :: Maybe Text
, _lwServiceIds' :: List ServiceId
, _lwFilter' :: Maybe Text
}
queryRequest ''ListWindows
lwQuery :: Lens' (Request ListWindows s b) (Maybe Text)
lwQuery = upd.lwQuery'
lwServiceIds :: Lens' (Request ListWindows s b) [ServiceId]
lwServiceIds = upd.lwServiceIds'._L
lwFilter :: Lens' (Request ListWindows s b) (Maybe Text)
lwFilter = upd.lwFilter'
data Counts = Counts
{ _cOngoing :: !Int
, _cFuture :: !Int
, _cPast :: !Int
, _cAll :: !Int
} deriving (Eq, Show)
deriveRecord ''Counts
data ListWindowsResponse = ListWindowsResponse
{ _lwMaintenanceWindows :: [MaintenanceWindow]
, _lwCounts :: Counts
} deriving (Eq, Show)
deriveRecord ''ListWindowsResponse
listWindows :: Request ListWindows s ListWindowsResponse
listWindows =
mk ListWindows
{ _lwQuery' = Nothing
, _lwServiceIds' = mempty
, _lwFilter' = Nothing
} & path .~ windows
data CreateWindow' = CreateWindow'
{ _cwStartTime' :: Date
, _cwEndTime' :: Date
, _cwDescription' :: Maybe Text
, _cwServiceIds' :: [ServiceId]
} deriving (Eq, Show)
deriveRecord ''CreateWindow'
data CreateWindow = CreateWindow
{ _cwRequesterId' :: Maybe RequesterId
, _cwMaintenanceWindow' :: CreateWindow'
} deriving (Eq, Show)
jsonRequest ''CreateWindow
cwStartTime :: Lens' (Request CreateWindow s b) UTCTime
cwStartTime = upd.cwMaintenanceWindow'.cwStartTime'._D
cwEndTime :: Lens' (Request CreateWindow s b) UTCTime
cwEndTime = upd.cwMaintenanceWindow'.cwEndTime'._D
cwDescription :: Lens' (Request CreateWindow s b) (Maybe Text)
cwDescription = upd.cwMaintenanceWindow'.cwDescription'
cwServiceIds :: Lens' (Request CreateWindow s b) [ServiceId]
cwServiceIds = upd.cwMaintenanceWindow'.cwServiceIds'
createWindow :: RequesterId
-> UTCTime
-> UTCTime
-> [ServiceId]
-> Request CreateWindow s MaintenanceWindow
createWindow r s e xs =
auth (createWindowBasic s e xs) & upd.cwRequesterId' ?~ r
createWindowBasic :: UTCTime
-> UTCTime
-> [ServiceId]
-> Request CreateWindow 'Basic MaintenanceWindow
createWindowBasic s e xs =
mk CreateWindow
{ _cwRequesterId' = Nothing
, _cwMaintenanceWindow' = CreateWindow'
{ _cwStartTime' = D s
, _cwEndTime' = D e
, _cwDescription' = Nothing
, _cwServiceIds' = xs
}
} & meth .~ POST
& path .~ windows
getWindow :: WindowId -> Request Empty s MaintenanceWindow
getWindow w = empty & path .~ windows % w
data UpdateWindow = UpdateWindow
{ _uwStartTime' :: Maybe Date
, _uwEndTime' :: Maybe Date
, _uwDescription' :: Maybe Text
, _uwServiceIds' :: Maybe [ServiceId]
} deriving (Eq, Show)
jsonRequest ''UpdateWindow
uwStartTime :: Lens' (Request UpdateWindow s b) (Maybe Date)
uwStartTime = upd.uwStartTime'
uwEndTime :: Lens' (Request UpdateWindow s b) (Maybe Date)
uwEndTime = upd.uwEndTime'
uwDescription :: Lens' (Request UpdateWindow s b) (Maybe Text)
uwDescription = upd.uwDescription'
uwServiceIds :: Lens' (Request UpdateWindow s b) (Maybe [ServiceId])
uwServiceIds = upd.uwServiceIds'
updateWindow :: WindowId -> Request UpdateWindow s MaintenanceWindow
updateWindow w =
mk UpdateWindow
{ _uwStartTime' = Nothing
, _uwEndTime' = Nothing
, _uwDescription' = Nothing
, _uwServiceIds' = Nothing
} & meth .~ PUT
& path .~ windows % w
deleteWindow :: WindowId -> Request Empty s Empty
deleteWindow w = empty & meth .~ DELETE & path .~ windows % w