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

namespace ERPCore.Controllers.Hrm;

/// <summary>Effective-dated EPF/ETF settings (docs/13-BACKEND-HRM-API.md §6).</summary>
[Route("api/v1/payroll-statutory-settings")]
public sealed class PayrollStatutorySettingsController : ApiControllerBase
{
    private readonly IPayrollStatutorySettingService _settings;
    private readonly ICurrentUser _currentUser;

    public PayrollStatutorySettingsController(IPayrollStatutorySettingService settings, ICurrentUser currentUser)
    {
        _settings = settings;
        _currentUser = currentUser;
    }

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

    [HttpPost]
    [ProducesResponseType(typeof(PayrollStatutorySettingDto), StatusCodes.Status201Created)]
    public async Task<ActionResult<PayrollStatutorySettingDto>> Create([FromBody] UpsertPayrollStatutorySettingRequest request, CancellationToken ct)
    {
        var result = await _settings.CreateAsync(request, _currentUser.AuditUserId, ct);
        return Created($"/api/v1/payroll-statutory-settings/{result.PayrollStatutorySettingId}", result);
    }
}
