darkwing/server/dtos/entities/
team_dto.rs

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
//! Data transfer objects for team-related API responses.
//!
//! This module contains DTOs that represent team data in a format suitable for
//! API responses. It handles the conversion of internal team models to API-safe
//! representations and provides utility methods for checking team status and
//! capabilities.

use time::PrimitiveDateTime;

use crate::database::team::{Plan, Team};

/// Data transfer object representing a team in API responses.
///
/// This DTO contains all the essential information about a team that is safe
/// to expose through the API, including subscription details and resource
/// limits.
#[derive(Debug)]
pub struct ResponseTeamDto {
  /// Unique identifier of the team
  pub id: u64,
  /// Name of the team
  pub name: String,
  /// Current subscription plan of the team
  pub plan: Plan,
  /// Maximum number of users allowed in the team
  pub users_limit: u64,
  /// Maximum number of browser profiles the team can create
  pub browser_profiles_limit: u64,
  /// Date and time when the team's subscription expires
  pub subscription_expiration: PrimitiveDateTime,
}

/// Implements conversion from database Team model to ResponseTeamDto
impl From<Team> for ResponseTeamDto {
  fn from(value: Team) -> Self {
    ResponseTeamDto {
      id: value.id,
      name: value.name.clone(),
      users_limit: value.usersLimit,
      browser_profiles_limit: value.browserProfilesLimit,
      subscription_expiration: value.subscriptionExpiration,
      plan: value.get_plan(),
    }
  }
}

impl ResponseTeamDto {
  /// Checks if the team is on a completely free plan.
  ///
  /// A team is considered to be on a fully free plan if:
  /// - Their plan type is `Free`
  /// - They have the default limit of 10 browser profiles
  ///
  /// # Returns
  /// - `true` if the team is on a completely free plan
  /// - `false` if the team has any paid features or modified limits
  pub fn is_fully_free_plan(&self) -> bool {
    self.plan == Plan::Free && self.browser_profiles_limit == 10
  }
}