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

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

            return Ok(result);
        }
    }
}
