using Entities.Contracts;
using Entities.DTO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using TechHelper.Server.Services;
using TechHelper.Services;

namespace TechHelper.Server.Controllers
{
	[Route("api/user")]
	[ApiController]
	public class UserController : ControllerBase
	{
		private IUserSerivces _userSerivces;
		private IClassService _classService;
		private UserManager<User> _userManager;
		public UserController(IClassService classService, UserManager<User> userManager, IUserSerivces userSerivces)
		{
			_classService = classService;
			_userManager = userManager;
			_userSerivces = userSerivces;
		}


		[HttpPost("get")]
		public async Task<IActionResult> GetAsync(
			[FromBody] UserRegistrationToClassDto toClass)
		{
			return Ok();
		}



		[HttpGet("restoreUserRole")]
		public async Task<IActionResult> RestoreUserRole()
		{
			var user = await _userManager.FindByEmailAsync(User.Identity.Name);

			if (user == null) return NotFound();
			if (User.IsInRole("Teacher") || User.IsInRole("Student"))
				return Ok();
			var result = await _userSerivces.RestoreUserRoleInformation(user);
			if (result.Status)
				return Ok();
			else
				return Unauthorized();
		}
	}
}
