using Bit.Core.Entities;
using Bit.Core.Exceptions;
using Bit.Core.Models.StaticStore;
namespace Bit.Core.Models.Business;
public class SecretsManagerSubscriptionUpdate
{
public Organization Organization { get; set; }
///
/// The total seats the organization will have after the update, including any base seats included in the plan
///
public int? SmSeats { get; set; }
///
/// The new autoscale limit for seats, expressed as a total (not an adjustment).
/// This may or may not be the same as the current autoscale limit.
///
public int? MaxAutoscaleSmSeats { get; set; }
///
/// The total service accounts the organization will have after the update, including the base service accounts
/// included in the plan
///
public int? SmServiceAccounts { get; set; }
///
/// The new autoscale limit for service accounts, expressed as a total (not an adjustment).
/// This may or may not be the same as the current autoscale limit.
///
public int? MaxAutoscaleSmServiceAccounts { get; set; }
///
/// The proration date for the subscription update (optional)
///
public DateTime? ProrationDate { get; set; }
///
/// Whether the subscription update is a result of autoscaling
///
public bool Autoscaling { get; init; }
///
/// The seats the organization will have after the update, excluding the base seats included in the plan
/// Usually this is what the organization is billed for
///
public int SmSeatsExcludingBase => SmSeats.HasValue ? SmSeats.Value - Plan.BaseSeats : 0;
///
/// The seats the organization will have after the update, excluding the base seats included in the plan
/// Usually this is what the organization is billed for
///
public int SmServiceAccountsExcludingBase => SmServiceAccounts.HasValue ? SmServiceAccounts.Value - Plan.BaseServiceAccount.GetValueOrDefault() : 0;
public bool SmSeatsChanged => SmSeats != Organization.SmSeats;
public bool SmServiceAccountsChanged => SmServiceAccounts != Organization.SmServiceAccounts;
public bool MaxAutoscaleSmSeatsChanged => MaxAutoscaleSmSeats != Organization.MaxAutoscaleSmSeats;
public bool MaxAutoscaleSmServiceAccountsChanged =>
MaxAutoscaleSmServiceAccounts != Organization.MaxAutoscaleSmServiceAccounts;
public Plan Plan => Utilities.StaticStore.GetSecretsManagerPlan(Organization.PlanType);
public SecretsManagerSubscriptionUpdate(
Organization organization,
int seatAdjustment, int? maxAutoscaleSeats,
int serviceAccountAdjustment, int? maxAutoscaleServiceAccounts) : this(organization, false)
{
AdjustSeats(seatAdjustment);
AdjustServiceAccounts(serviceAccountAdjustment);
MaxAutoscaleSmSeats = maxAutoscaleSeats;
MaxAutoscaleSmServiceAccounts = maxAutoscaleServiceAccounts;
}
public SecretsManagerSubscriptionUpdate(Organization organization, bool autoscaling)
{
if (organization == null)
{
throw new NotFoundException("Organization is not found.");
}
Organization = organization;
if (Plan == null)
{
throw new NotFoundException("Invalid Secrets Manager plan.");
}
SmSeats = organization.SmSeats;
MaxAutoscaleSmSeats = organization.MaxAutoscaleSmSeats;
SmServiceAccounts = organization.SmServiceAccounts;
MaxAutoscaleSmServiceAccounts = organization.MaxAutoscaleSmServiceAccounts;
Autoscaling = autoscaling;
}
public void AdjustSeats(int adjustment)
{
SmSeats = SmSeats.GetValueOrDefault() + adjustment;
}
public void AdjustServiceAccounts(int adjustment)
{
SmServiceAccounts = SmServiceAccounts.GetValueOrDefault() + adjustment;
}
}