using Core.Interfaces;
using Microsoft.AspNetCore.Mvc;

namespace phronCare.API.Controllers.Sales
{
    [Route("api/[controller]")]
    [ApiController]
    public class DocumentTypeController : ControllerBase
    {
        private readonly IDocumentTypeDom _documentTypeService;
        public DocumentTypeController(IDocumentTypeDom documentTypeService)
        {
            _documentTypeService = documentTypeService ?? throw new ArgumentNullException(nameof(documentTypeService));
        }
        [HttpGet("GetAll")]
        public async Task<IActionResult> GetAll()
        {
            try
            {
                var result = await _documentTypeService.GetAllAsync();
                return Ok(result);
            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
            }
        }
        [HttpGet("GetByName/{name}")]
        public async Task<IActionResult> GetByName(string name)
        {
            var result = await _documentTypeService.GetByNameAsync(name);
            if (result == null)
                return NotFound($"No se encontró un tipo de cuenta con el nombre '{name}'.");

            return Ok(result);
        }
    }
}
