using NexusReader.Application.Constants;

namespace NexusReader.Application.DTOs.User;

public record UserProfileDto
{
    public string Email { get; init; } = string.Empty;
    public string UserId { get; init; } = string.Empty;
    public int AITokensUsed { get; init; }
    public Guid TenantId { get; init; }
    
    /// <summary>
    /// Relational data for the current subscription plan.
    /// </summary>
    public SubscriptionPlanDto Plan { get; init; } = new();

    public int AverageQuizScore { get; init; }
    
    public string? DisplayName { get; init; }
    public int BooksReadCount { get; init; }
    public int ConceptsMappedCount { get; init; }
    public LastReadBookDto? LastReadBook { get; init; }
    public IReadOnlyList<QuizResultDto> RecentQuizzes { get; init; } = Array.Empty<QuizResultDto>();
    public IReadOnlyList<MappedConceptDto> MappedConcepts { get; init; } = Array.Empty<MappedConceptDto>();
    public string[] Roles { get; init; } = Array.Empty<string>();

    // Helper properties for UI compatibility
    public string CurrentPlan => Plan?.Name ?? PlanConstants.DefaultPlanName;
    public int AITokenLimit => Plan?.AITokenLimit ?? PlanConstants.DefaultTokenLimit;
    public string LastReadBookTitle => LastReadBook?.Title ?? PlanConstants.DefaultActivityLabel;
}

public record MappedConceptDto
{
    public string Id { get; init; } = string.Empty;
    public string Type { get; init; } = string.Empty;
    public string Content { get; init; } = string.Empty;
    public string DisplayLabel => Content.Length > 25 ? Content.Substring(0, 22) + "..." : Content;
}

public record LastReadBookDto
{
    public Guid Id { get; init; }
    public string Title { get; init; } = string.Empty;
    public AuthorDto Author { get; init; } = new();
    public string? CoverUrl { get; init; }
    public double Progress { get; init; }
    public string? LastChapter { get; init; }
    public int LastChapterIndex { get; init; }
    public string? Description { get; init; }
    public bool IsReadyForReading { get; init; }
}

public record QuizResultDto
{
    public Guid Id { get; init; }
    public string Topic { get; init; } = string.Empty;
    public int Score { get; init; }
    public int TotalQuestions { get; init; }
    public double Percentage { get; init; }
    public DateTime CompletedDate { get; init; }
}
