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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]

use crate::error;
use error::Error;
use error::Error::InvalidJobState;

use std::str::FromStr;

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct LogCollectionJob<'a> {
  resourceType: &'a str,
  resourceName: &'a str,
  redacted: bool,
  sizeRequestedPerFileBytes: u64,
  logTypes: Vec<&'a str>,
}

impl LogCollectionJob<'_> {
  pub(crate) fn from(replica_set_name: &str, bytes: u64) -> LogCollectionJob {
    LogCollectionJob {
      resourceName: replica_set_name,
      sizeRequestedPerFileBytes: bytes,
      resourceType: "REPLICASET",
      redacted: true,
      logTypes: vec!["FTDC"],
    }
  }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Clusters {
  pub results: Vec<Shard>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Shard {
  pub(crate) userAlias: String,
  pub(crate) typeName: String,
  pub(crate) replicaSetName: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct JobId {
  pub(crate) id: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct JobStatus<'a> {
  pub(crate) id: &'a str,
  pub(crate) downloadUrl: &'a str,
  pub(crate) status: &'a str,
}

#[derive(Debug, Serialize, Deserialize)]
pub enum JobState {
  Succcess,
  Failure,
  InProgress,
  MarkedForExpiry,
  Expired,
}

impl FromStr for JobState {
  type Err = Error;

  fn from_str(s: &str) -> Result<Self, Error> {
    match s {
      "SUCCESS" => Ok(JobState::Succcess),
      "FAILURE" => Ok(JobState::Failure),
      "IN_PROGRESS" => Ok(JobState::InProgress),
      "MARKED_FOR_EXPIRY" => Ok(JobState::MarkedForExpiry),
      "EXPIRED" => Ok(JobState::Expired),
      invalid => Err(InvalidJobState(invalid.to_string())),
    }
  }
}