using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.UserRep;
using DigitalData.UserManager.Domain.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace DigitalData.UserManager.API.Controllers
{
    [Authorize]
    public class UserRepController : BaseAuthController<IUserRepService, UserRepCreateDto, UserRepReadDto, UserRepUpdateDto, UserRep>
    {
        public UserRepController(ILogger<UserRepController> logger, IUserRepService service, IUserService userService) : base(logger, service, userService)
        {
        }

        [NonAction]
        public override Task<IActionResult> GetAll()
        {
            return base.GetAll();
        }

        [HttpGet]
        public async Task<IActionResult> GetAll(bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false, int? userId = null, int? groupId = null)
        {
            try
            {
                return await _service.ReadAllAsync(withUser, withRepGroup, withGroup, withRepUser, userId, groupId).ThenAsync(Ok, IActionResult (m, n) =>
                {
                    _logger.LogNotice(n);
                    return NotFound();
                });
                
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "{Message}", ex.Message);
                return StatusCode(StatusCodes.Status500InternalServerError);
            }
        }
    }
}