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

namespace ERPCore.Controllers;

/// <summary>Stock-adjustment endpoints (docs/11 §5.5).</summary>
[Route("api/v1/stock-adjustments")]
public sealed class StockAdjustmentsController : ApiControllerBase
{
    private readonly IAdjustmentService _adjustments;

    public StockAdjustmentsController(IAdjustmentService adjustments) => _adjustments = adjustments;

    /// <summary>Create + auto-post an adjustment (mandatory reason code; decrease FIFO-consumes).</summary>
    [HttpPost]
    [ProducesResponseType(typeof(AdjustmentDto), StatusCodes.Status201Created)]
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
    [ProducesResponseType(StatusCodes.Status409Conflict)]
    [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
    public async Task<ActionResult<AdjustmentDto>> Create([FromBody] CreateAdjustmentRequest request, CancellationToken ct)
    {
        var dto = await _adjustments.CreateAsync(request, ct);
        return Created($"/api/v1/stock-adjustments/{dto.AdjustmentId}", dto);
    }
}
