using System;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class User
{
    [Header("Personal data")]
    // User nickname
    public string username;
    // User avatar
    public Sprite avatar;

    [Header("Personal settings")]
    // TODO: set personal settings and preferences

    [Header("Progress")]
    // Total playtime
    public double playtime;
    [SerializeField]
    // List of courses a user started/completed
    public List<Progress> courses = new List<Progress>();
    [SerializeField]
    // List of minigames a user played
    public List<Progress> minigames = new List<Progress>();

    // Get a list of all recently started courses, returns a list of tuples of `<CourseIndex idx, float courseProgress>`
    public List<Tuple<CourseIndex, float>> GetRecentCourses()
    {
        // TODO: return better results (for now only return all courses)
        List<Tuple<CourseIndex, float>> recentCourses = new List<Tuple<CourseIndex, float>>();
        foreach (Progress courseProgress in courses)
        {
            CourseIndex idx = courseProgress.Get<CourseIndex>("courseIndex");
            float progress = courseProgress.Get<float>("courseProgress");
            recentCourses.Add(Tuple.Create<CourseIndex, float>(idx, progress));
        }
        return recentCourses;
    }

    // Get a list of all recommended courses, returns a list of tuples of `<CourseIndex idx, float courseProgress>`
    public List<Tuple<CourseIndex, float>> GetRecommendedCourses()
    {
        List<Tuple<CourseIndex, float>> recommenedCourses = new List<Tuple<CourseIndex, float>>();
        if (courses.Count == 0)
        {
            recommenedCourses.Add(Tuple.Create<CourseIndex, float>(CourseIndex.FINGERSPELLING, 0.0f));
        }
        else
        {
            // TODO: return better results (for now only return all courses)
            foreach (Progress courseProgress in courses)
            {
                CourseIndex idx = courseProgress.Get<CourseIndex>("courseIndex");
                float progress = courseProgress.Get<float>("courseProgress");
                recommenedCourses.Add(Tuple.Create<CourseIndex, float>(idx, progress));
            }
        }

        return recommenedCourses;
    }
}
