|
| 1 | +use serde::{Deserialize, Serialize}; |
| 2 | + |
| 3 | +#[derive(Clone, Debug, PartialEq, Default)] |
| 4 | +pub struct ReportPagination { |
| 5 | + pub page_size: Option<i32>, |
| 6 | + pub page_number: Option<i32>, |
| 7 | +} |
| 8 | + |
| 9 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 10 | +pub(crate) struct FetchReportQuery { |
| 11 | + pub(crate) report_interval: ReportInterval, |
| 12 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 13 | + pub(crate) page_size: Option<i32>, |
| 14 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 15 | + pub(crate) page_number: Option<i32>, |
| 16 | +} |
| 17 | + |
| 18 | +#[derive(Clone, Debug, PartialEq)] |
| 19 | +pub enum OrgReportType { |
| 20 | + Attrition, |
| 21 | + Growth, |
| 22 | + Reengagement, |
| 23 | + Churn, |
| 24 | +} |
| 25 | + |
| 26 | +impl OrgReportType { |
| 27 | + pub fn as_str(&self) -> &'static str { |
| 28 | + match self { |
| 29 | + OrgReportType::Attrition => "attrition", |
| 30 | + OrgReportType::Growth => "growth", |
| 31 | + OrgReportType::Reengagement => "reengagement", |
| 32 | + OrgReportType::Churn => "churn", |
| 33 | + } |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +#[derive(Clone, Debug, PartialEq)] |
| 38 | +pub enum UserReportType { |
| 39 | + TopInviter, |
| 40 | + Champion, |
| 41 | + Reengagement, |
| 42 | + Churn, |
| 43 | +} |
| 44 | + |
| 45 | +impl UserReportType { |
| 46 | + pub fn as_str(&self) -> &'static str { |
| 47 | + match self { |
| 48 | + UserReportType::TopInviter => "top_inviter", |
| 49 | + UserReportType::Champion => "champion", |
| 50 | + UserReportType::Reengagement => "reengagement", |
| 51 | + UserReportType::Churn => "churn", |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 57 | +#[serde(untagged)] |
| 58 | +pub(crate) enum ReportInterval { |
| 59 | + TopInviter(TopInviterReportInterval), |
| 60 | + Champion(ChampionReportInterval), |
| 61 | + Reengagement(ReengagementReportInterval), |
| 62 | + Churn(ChurnReportInterval), |
| 63 | + Attrition(AttritionReportInterval), |
| 64 | + Growth(GrowthReportInterval), |
| 65 | +} |
| 66 | + |
| 67 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 68 | +pub enum TopInviterReportInterval { |
| 69 | + #[serde(rename = "30")] |
| 70 | + ThirtyDays, |
| 71 | + #[serde(rename = "60")] |
| 72 | + SixtyDays, |
| 73 | + #[serde(rename = "90")] |
| 74 | + NinetyDays, |
| 75 | +} |
| 76 | + |
| 77 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 78 | +pub enum ChampionReportInterval { |
| 79 | + #[serde(rename = "30")] |
| 80 | + ThirtyDays, |
| 81 | + #[serde(rename = "60")] |
| 82 | + SixtyDays, |
| 83 | + #[serde(rename = "90")] |
| 84 | + NinetyDays, |
| 85 | +} |
| 86 | + |
| 87 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 88 | +pub enum ReengagementReportInterval { |
| 89 | + #[serde(rename = "Weekly")] |
| 90 | + Weekly, |
| 91 | + #[serde(rename = "Monthly")] |
| 92 | + Monthly, |
| 93 | +} |
| 94 | + |
| 95 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 96 | +pub enum ChurnReportInterval { |
| 97 | + #[serde(rename = "7")] |
| 98 | + SevenDays, |
| 99 | + #[serde(rename = "14")] |
| 100 | + FourteenDays, |
| 101 | + #[serde(rename = "30")] |
| 102 | + ThirtyDays, |
| 103 | +} |
| 104 | + |
| 105 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 106 | +pub enum AttritionReportInterval { |
| 107 | + #[serde(rename = "30")] |
| 108 | + ThirtyDays, |
| 109 | + #[serde(rename = "60")] |
| 110 | + SixtyDays, |
| 111 | + #[serde(rename = "90")] |
| 112 | + NinetyDays, |
| 113 | +} |
| 114 | + |
| 115 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 116 | +pub enum GrowthReportInterval { |
| 117 | + #[serde(rename = "30")] |
| 118 | + ThirtyDays, |
| 119 | + #[serde(rename = "60")] |
| 120 | + SixtyDays, |
| 121 | + #[serde(rename = "90")] |
| 122 | + NinetyDays, |
| 123 | +} |
| 124 | + |
| 125 | +#[derive(Debug, Clone, Deserialize)] |
| 126 | +pub struct OrgReportRecord { |
| 127 | + pub id: String, |
| 128 | + pub report_id: String, |
| 129 | + pub org_id: String, |
| 130 | + pub name: String, |
| 131 | + pub num_users: i32, |
| 132 | + pub org_created_at: i64, |
| 133 | + pub extra_properties: Option<serde_json::Value>, |
| 134 | +} |
| 135 | + |
| 136 | +#[derive(Deserialize)] |
| 137 | +pub struct OrgReport { |
| 138 | + pub org_reports: Vec<OrgReportRecord>, |
| 139 | + pub current_page: i64, |
| 140 | + pub total_count: i64, |
| 141 | + pub page_size: i64, |
| 142 | + pub has_more_results: bool, |
| 143 | + pub report_time: i64, |
| 144 | +} |
| 145 | + |
| 146 | +#[derive(Debug, Clone, Deserialize)] |
| 147 | +pub struct UserReportRecord { |
| 148 | + pub id: String, |
| 149 | + pub report_id: String, |
| 150 | + pub user_id: String, |
| 151 | + pub user_created_at: i64, |
| 152 | + pub username: Option<String>, |
| 153 | + pub first_name: Option<String>, |
| 154 | + pub last_name: Option<String>, |
| 155 | + pub email: String, |
| 156 | + pub last_active_at: i64, |
| 157 | + pub org_data: serde_json::Value, |
| 158 | + pub extra_properties: Option<serde_json::Value>, |
| 159 | +} |
| 160 | +#[derive(Deserialize)] |
| 161 | +pub struct UserReportPage { |
| 162 | + pub user_reports: Vec<UserReportRecord>, |
| 163 | + pub current_page: i64, |
| 164 | + pub total_count: i64, |
| 165 | + pub page_size: i64, |
| 166 | + pub has_more_results: bool, |
| 167 | + pub report_time: i64, |
| 168 | +} |
0 commit comments