using Reconstruction;
using System.Collections.ObjectModel;

namespace Reconstruction.Functions
{ 
    public static class Display
    {
        public static void ShowUserList()
        {
            Console.WriteLine("Login  |" + "  Lastname  |" + "  Firstname  |" + "  Middlename ");
            foreach (User s in Service.UserCollection)
            {
                Console.WriteLine(s.Login + ' ' + s.Lastname + ' ' + s.Firstname + ' ' + s.Middlename);
            }

            Console.ReadKey();  

        }



        public static void ShowProfileData()
        {
            Console.WriteLine("User Name: "     + Service.LoggedUser.Login 
                          + "\nFirst name: "    + Service.LoggedUser.Firstname 
                          + "\nSurname: "       + Service.LoggedUser.Lastname 
                          + "\nPatronimic: "    + Service.LoggedUser.Middlename 
                          + "\nPhone: "         + Service.LoggedUser.Phone 
                          + "\nTasks: ");
            Service.db.Tasks.Where(t => t.AccUserId == Service.LoggedUser.Id).ToList().ForEach(t => global::System.Console.Write(t.Title + " "));
        
            Console.ReadKey();
        }


        public static void ShowAvailableTask()
        {
            ObservableCollection<Task> TaskCollection = new ObservableCollection<Task>(Service.db.Tasks.ToList());

            foreach (Task t in TaskCollection)
            {
                User user = (User)Service.db.Users.Where(u => u.Id == t.CreatorUserId).SingleOrDefault();

                if(user == null)
                {
                    user.Login = "No user attached";
                }

                if(t.StatusId == 1)
                {
                    Console.WriteLine("Title: " + t.Title +
                                      "\nDescription: " + t.Description +
                                      "\nCreated by " + user.Login + "\n");
                }


            }
            Console.ReadKey();
        }

    }
}
