using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Domain.UseCase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Posechaemost.UI
{
    public class UserConsoleUI
    {
        UserUseCase _userUseCase;
        public UserConsoleUI(UserUseCase userUseCase) {
            _userUseCase = userUseCase;
        }

        public void RemoveUserById(int userId) {

            string output = _userUseCase.RemoveUserById(userId) ? "Пользователь удален" : "Пользователь не удален";
            Console.WriteLine(output);
        }
        
        public void DisplayAllUsers()
        {
            StringBuilder userOutput = new StringBuilder();
            foreach (var user in _userUseCase.GetAllUsers())
            {
                userOutput.AppendLine($"{user.UserId}\t{user.FIO}\t{user.GroupId}");
            }
            Console.WriteLine(userOutput);
        }

        public void GetUserById(int userId) {
            StringBuilder userOutput = new StringBuilder();    
            var user = _userUseCase.GetUserById(userId);
            userOutput.AppendLine($"{user.UserId}\t{user.FIO}\t{user.GroupId}");
            Console.WriteLine(userOutput);
        }   

        public void UpdateUserById(int userId, String name, int groupId) {
            StringBuilder userOutput = new StringBuilder();    
            var user = _userUseCase.UpdateUserById(userId, name, groupId) ? "Пользователь обновлен" : "Пользователь не обновлен";
            Console.WriteLine(userOutput);
        }
    }
}
    

