using ERPCore.Dtos.Hrm;
using ERPCore.Services.Interfaces;
using Microsoft.AspNetCore.Mvc;

namespace ERPCore.Controllers.Hrm;

/// <summary>Configurable APIT-style tax slabs (docs/13-BACKEND-HRM-API.md §6).</summary>
[Route("api/v1/tax-slabs")]
public sealed class TaxSlabsController : ApiControllerBase
{
    private readonly ITaxSlabService _taxSlabs;

    public TaxSlabsController(ITaxSlabService taxSlabs) => _taxSlabs = taxSlabs;

    [HttpGet]
    [ProducesResponseType(typeof(List<TaxSlabDto>), StatusCodes.Status200OK)]
    public async Task<ActionResult<List<TaxSlabDto>>> List(CancellationToken ct)
        => Ok(await _taxSlabs.ListAsync(ct));

    [HttpPost]
    [ProducesResponseType(typeof(TaxSlabDto), StatusCodes.Status201Created)]
    [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
    public async Task<ActionResult<TaxSlabDto>> Create([FromBody] CreateTaxSlabRequest request, CancellationToken ct)
    {
        var result = await _taxSlabs.CreateAsync(request, ct);
        return Created($"/api/v1/tax-slabs/{result.TaxSlabId}", result);
    }
}
