use super::{ApiLinks, ApiMeta};
use super::{HasPagination, HasResponse, HasValue};
use crate::method::{Get, List};
use crate::request::ActionRequest;
use crate::request::Request;
use crate::{ROOT_URL, STATIC_URL_ERROR};
use chrono::{DateTime, Utc};
use getset::{Getters, Setters};
use url::Url;
const ACTIONS_SEGMENT: &str = "actions";
#[derive(Deserialize, Serialize, Debug, Clone, Getters, Setters)]
#[get = "pub"]
pub struct Action {
id: usize,
status: String,
started_at: DateTime<Utc>,
completed_at: Option<DateTime<Utc>>,
resource_id: usize,
resource_type: String,
region_slug: Option<String>
}
impl Action {
pub fn get(id: usize) -> ActionRequest<Get, Action> {
let mut url = ROOT_URL.clone();
url.path_segments_mut()
.expect(STATIC_URL_ERROR)
.push(ACTIONS_SEGMENT)
.push(&id.to_string());
Request::new(url)
}
pub fn list() -> ActionRequest<List, Vec<Action>> {
let mut url = ROOT_URL.clone();
url.path_segments_mut()
.expect(STATIC_URL_ERROR)
.push(ACTIONS_SEGMENT);
Request::new(url)
}
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ActionResponse {
action: Action
}
impl HasValue for ActionResponse {
type Value = Action;
fn value(self) -> Action {
self.action
}
}
impl HasResponse for Action {
type Response = ActionResponse;
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ActionListResponse {
actions: Vec<Action>,
links: ApiLinks,
meta: ApiMeta
}
impl HasResponse for Vec<Action> {
type Response = ActionListResponse;
}
impl HasPagination for ActionListResponse {
fn next_page(&self) -> Option<Url> {
self.links.next()
}
}
impl HasValue for ActionListResponse {
type Value = Vec<Action>;
fn value(self) -> Vec<Action> {
self.actions
}
}