using Entities.Contracts;
using Entities.DTO;
using Microsoft.AspNetCore.Identity;
using SharedDATA.Api;
using TechHelper.Services;

namespace TechHelper.Server.Services
{
	public class UserServices : IUserSerivces
	{

		private readonly IUnitOfWork _unitOfWork;
		private readonly IClassService _classService;
		private readonly UserManager<User> _userManager;

		public UserServices(IUnitOfWork unitOfWork, IClassService classService, UserManager<User> userManager)
		{
			_unitOfWork = unitOfWork;
			_classService = classService;
			_userManager = userManager;
		}

		public Task<ApiResponse> AddAsync(User model)
		{
			throw new NotImplementedException();
		}

		public Task<ApiResponse> DeleteAsync(Guid id)
		{
			throw new NotImplementedException();
		}

		public Task<ApiResponse> GetAllAsync(QueryParameter query)
		{
			throw new NotImplementedException();
		}

		public Task<ApiResponse> GetAsync(Guid id)
		{
			throw new NotImplementedException();
		}

		public Task<ApiResponse> GetStudentDetailInfo(Guid userId)
		{
			throw new NotImplementedException();
		}

		public async Task<ApiResponse> RestoreUserRoleInformation(User user)
		{
			var result = await _classService.GetUserClassRole(user.Id);
			if (result.Status)
			{
				var classRole = result.Result as UserClassRoleDto;
				if (classRole != null)
				{
					if (!await _userManager.IsInRoleAsync(user, classRole.Role))
					{
						await _userManager.AddToRoleAsync(user, classRole.Role);

						return ApiResponse.Success();
					}
				}
			}
			return ApiResponse.Error();
		}

		public Task<ApiResponse> UpdateAsync(User model)
		{
			throw new NotImplementedException();
		}

		public Task<ApiResponse> VerifyUserInformation(Guid userId)
		{
			throw new NotImplementedException();
		}
	}
}
