using BCards.Web.Models; using Stripe; namespace BCards.Web.ViewModels; public class ManageSubscriptionViewModel { public User User { get; set; } = new(); public Stripe.Subscription? StripeSubscription { get; set; } public Models.Subscription? LocalSubscription { get; set; } public List PaymentHistory { get; set; } = new(); public List AvailablePlans { get; set; } = new(); public string? ErrorMessage { get; set; } public string? SuccessMessage { get; set; } // Propriedades calculadas public bool HasActiveSubscription => StripeSubscription?.Status == "active"; public bool CanUpgrade => HasActiveSubscription && User.CurrentPlan != "premium"; public bool CanDowngrade => HasActiveSubscription && User.CurrentPlan != "basic"; public bool WillCancelAtPeriodEnd => StripeSubscription?.CancelAtPeriodEnd == true; public DateTime? CurrentPeriodEnd => StripeSubscription?.CurrentPeriodEnd; public DateTime? NextBillingDate => !WillCancelAtPeriodEnd ? CurrentPeriodEnd : null; public decimal? MonthlyAmount => StripeSubscription?.Items?.Data?.FirstOrDefault()?.Price?.UnitAmount / 100m; public string? Currency => StripeSubscription?.Items?.Data?.FirstOrDefault()?.Price?.Currency?.ToUpper(); public string StatusDisplayName => (StripeSubscription?.Status) switch { "active" => "Ativa", "past_due" => "Em atraso", "canceled" => "Cancelada", "unpaid" => "Não paga", "incomplete" => "Incompleta", "incomplete_expired" => "Expirada", "trialing" => "Em período de teste", _ => "Desconhecido" }; public string PlanDisplayName => User.CurrentPlan switch { "basic" => "Básico", "professional" => "Profissional", "premium" => "Premium", _ => "Gratuito" }; } public class AvailablePlanViewModel { public string PlanType { get; set; } = string.Empty; public string DisplayName { get; set; } = string.Empty; public decimal Price { get; set; } public string PriceId { get; set; } = string.Empty; public int MaxLinks { get; set; } public bool AllowCustomThemes { get; set; } public bool AllowAnalytics { get; set; } public bool AllowCustomDomain { get; set; } public bool IsCurrentPlan { get; set; } public bool IsUpgrade { get; set; } public bool IsDowngrade { get; set; } public List Features { get; set; } = new(); } public class PaymentHistoryItemViewModel { public string InvoiceId { get; set; } = string.Empty; public DateTime Date { get; set; } public decimal Amount { get; set; } public string Currency { get; set; } = string.Empty; public string Status { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; public string? ReceiptUrl { get; set; } public string StatusDisplayName => Status switch { "paid" => "Pago", "open" => "Em aberto", "void" => "Cancelado", "uncollectible" => "Incobrável", _ => "Desconhecido" }; }