using ERPCore.Dtos.Common;
using ERPCore.Dtos.Uoms;
using ERPCore.Services.Interfaces;
using Microsoft.AspNetCore.Mvc;

namespace ERPCore.Controllers;

/// <summary>Unit-of-measure endpoints (docs/11-BACKEND-PHASE1.md §2.2).</summary>
[Route("api/v1/uoms")]
public sealed class UomsController : ApiControllerBase
{
    private readonly IUomService _uoms;

    public UomsController(IUomService uoms) => _uoms = uoms;

    [HttpGet]
    [ProducesResponseType(typeof(PagedResponse<UomDto>), StatusCodes.Status200OK)]
    public async Task<ActionResult<PagedResponse<UomDto>>> List([FromQuery] PageQuery query, CancellationToken ct)
        => Ok(await _uoms.ListAsync(query, ct));

    [HttpPost]
    [ProducesResponseType(typeof(UomDto), StatusCodes.Status201Created)]
    [ProducesResponseType(StatusCodes.Status409Conflict)]
    public async Task<ActionResult<UomDto>> Create([FromBody] CreateUomRequest request, CancellationToken ct)
    {
        var dto = await _uoms.CreateAsync(request, ct);
        return Created($"/api/v1/uoms/{dto.UomId}", dto);
    }
}
