namespace PlotLine.Models;

public sealed class SubscriptionLevel
{
    public int SubscriptionLevelID { get; set; }
    public string Name { get; set; } = string.Empty;
    public string DisplayName { get; set; } = string.Empty;
    public string? Description { get; set; }
    public int MaxBooks { get; set; }
    public int MaxChaptersPerBook { get; set; }
    public int MaxScenesPerBook { get; set; }
    public int MaxCharactersPerProject { get; set; }
    public int MaxStorageMB { get; set; }
    public int MaxCollaborators { get; set; }
    public bool IsActive { get; set; }
    public int SortOrder { get; set; }
    public DateTime CreatedDateUTC { get; set; }
    public DateTime ModifiedDateUTC { get; set; }
}

public class UserSubscription
{
    public int UserSubscriptionID { get; set; }
    public int UserID { get; set; }
    public int SubscriptionLevelID { get; set; }
    public DateTime StartDateUTC { get; set; }
    public DateTime? EndDateUTC { get; set; }
    public bool IsActive { get; set; }
    public bool IsTrial { get; set; }
    public DateTime? TrialExpiryDateUTC { get; set; }
    public DateTime CreatedDateUTC { get; set; }
    public DateTime ModifiedDateUTC { get; set; }
}

public sealed class UserSubscriptionDetail : UserSubscription
{
    public string Name { get; set; } = string.Empty;
    public string DisplayName { get; set; } = string.Empty;
    public string? Description { get; set; }
    public int MaxBooks { get; set; }
    public int MaxChaptersPerBook { get; set; }
    public int MaxScenesPerBook { get; set; }
    public int MaxCharactersPerProject { get; set; }
    public int MaxStorageMB { get; set; }
    public int MaxCollaborators { get; set; }
    public bool SubscriptionLevelIsActive { get; set; }
    public int SortOrder { get; set; }
}

public sealed class SubscriptionLimitResult
{
    public bool Allowed { get; init; }
    public int CurrentUsage { get; init; }
    public int MaximumAllowed { get; init; }
    public string Message { get; init; } = string.Empty;

    public static SubscriptionLimitResult AllowedResult(int currentUsage, int maximumAllowed) => new()
    {
        Allowed = true,
        CurrentUsage = currentUsage,
        MaximumAllowed = maximumAllowed
    };

    public static SubscriptionLimitResult Blocked(int currentUsage, int maximumAllowed, string message) => new()
    {
        Allowed = false,
        CurrentUsage = currentUsage,
        MaximumAllowed = maximumAllowed,
        Message = message
    };
}
