using ManagerService.DTOs; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace ManagerService.Data { /// /// Instance Information /// public class Instance { [Key] [Required] public string Id { get; set; } [Required] public string Name { get; set; } // UNIQUE !.. public DateTime DateCreation { get; set; } public string PinCode { get; set; } public bool IsPushNotification { get; set; } public bool IsStatistic { get; set; } public bool IsMobile { get; set; } public bool IsTablet { get; set; } public bool IsWeb { get; set; } public bool IsVR { get; set; } public bool IsAssistant { get; set; } public string? SubscriptionPlanId { get; set; } [ForeignKey("SubscriptionPlanId")] public SubscriptionPlan? SubscriptionPlan { get; set; } public int AiRequestsThisMonth { get; set; } = 0; public string AiUsageMonthKey { get; set; } = ""; public long StorageQuotaBytes { get; set; } = 0; public int AiRequestsPerMonth { get; set; } = 0; public bool HasStats { get; set; } = false; public int StatsHistoryDays { get; set; } = 30; public bool HasAdvancedStats { get; set; } = false; public InstanceDTO ToDTO(List applicationInstanceDTOs) { return new InstanceDTO() { id = Id, name = Name, dateCreation = DateCreation, pinCode = PinCode, isPushNotification = IsPushNotification, isStatistic = IsStatistic, isMobile = IsMobile, isTablet = IsTablet, isWeb = IsWeb, isVR = IsVR, isAssistant = IsAssistant, subscriptionPlanId = SubscriptionPlanId, subscriptionPlan = SubscriptionPlan?.ToDTO(), aiRequestsThisMonth = AiRequestsThisMonth, aiUsageMonthKey = AiUsageMonthKey, storageQuotaBytes = StorageQuotaBytes, aiRequestsPerMonth = AiRequestsPerMonth, hasStats = HasStats, statsHistoryDays = StatsHistoryDays, hasAdvancedStats = HasAdvancedStats, applicationInstanceDTOs = applicationInstanceDTOs }; } public Instance FromDTO(InstanceDTO instanceDTO) { Name = instanceDTO.name; DateCreation = instanceDTO.dateCreation != null ? instanceDTO.dateCreation.Value : DateTime.Now.ToUniversalTime(); PinCode = instanceDTO.pinCode; IsPushNotification = instanceDTO.isPushNotification ?? false; IsStatistic = instanceDTO.isStatistic ?? false; IsMobile = instanceDTO.isMobile ?? false; IsTablet = instanceDTO.isTablet ?? false; IsWeb = instanceDTO.isWeb ?? false; IsVR = instanceDTO.isVR ?? false; IsAssistant = instanceDTO.isAssistant ?? false; if (instanceDTO.subscriptionPlanId != null) SubscriptionPlanId = instanceDTO.subscriptionPlanId; if (instanceDTO.storageQuotaBytes.HasValue) StorageQuotaBytes = instanceDTO.storageQuotaBytes.Value; if (instanceDTO.aiRequestsPerMonth.HasValue) AiRequestsPerMonth = instanceDTO.aiRequestsPerMonth.Value; if (instanceDTO.hasStats.HasValue) HasStats = instanceDTO.hasStats.Value; if (instanceDTO.statsHistoryDays.HasValue) StatsHistoryDays = instanceDTO.statsHistoryDays.Value; if (instanceDTO.hasAdvancedStats.HasValue) HasAdvancedStats = instanceDTO.hasAdvancedStats.Value; return this; } } }