1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! API Action shutdown-process
//!
//! [Official Documentation](https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#shutdown-process)

use serde::{Deserialize, Serialize};

use crate::types::action::StatusResponse;
use crate::types::query::ResultsWrapper;
use crate::types::rest::{RestApiEndpoint, RestApiResponse};

/// REST API Endpoint for the shutdown-process call
#[derive(Debug, Clone, derive_builder::Builder, Serialize, Deserialize)]
pub struct ShutdownProcess {}

impl ShutdownProcess {
    /// create a new builder for this endpoint
    ///
    /// this is usually the first step to calling this REST API endpoint
    #[must_use]
    pub fn builder() -> ShutdownProcessBuilder {
        ShutdownProcessBuilder::default()
    }
}

impl RestApiEndpoint for ShutdownProcess {
    type RequestBody = ShutdownProcess;

    fn method(&self) -> Result<http::Method, crate::error::Error> {
        Ok(http::Method::POST)
    }

    fn url(&self, base_url: &url::Url) -> Result<url::Url, crate::error::Error> {
        base_url
            .join("v1/actions/shutdown-process")
            .map_err(crate::error::Error::CouldNotParseUrlFragment)
    }

    fn request_body(
        &self,
    ) -> Result<Option<std::borrow::Cow<Self::RequestBody>>, crate::error::Error>
    where
        Self::RequestBody: Clone + serde::Serialize + std::fmt::Debug,
    {
        Ok(Some(std::borrow::Cow::Borrowed(self)))
    }
}

impl RestApiResponse<ShutdownProcess> for ResultsWrapper<StatusResponse> {}