using IdokladSdk.Models.PriceListItem;
using IdokladSdk.Models.StockMovement;
using IdokladSdk.Models.Tag;
using Microsoft.AspNetCore.Mvc;
using Idoklad.Services;
namespace Idoklad.Controllers;
///
/// Price list items, stock movements and tags. Requires iDoklad credentials (headers or environment defaults).
///
[ApiController]
[Produces("application/json")]
[Tags("Catalog")]
public sealed class CatalogController : ControllerBase
{
private readonly CatalogService _service;
public CatalogController(CatalogService service) => _service = service;
// ---- Price list items ----
/// List price list items (paged).
[HttpGet("price-list-items")]
public async Task ListPriceListItems(int page = 1, int pageSize = 20, CancellationToken ct = default)
=> Ok(await _service.ListPriceListItemsAsync(page, pageSize, ct));
/// Get a pre-filled default model for creating a new price list item.
[HttpGet("price-list-items/default")]
public async Task PriceListItemDefault(CancellationToken ct)
=> Ok(await _service.PriceListItemDefaultAsync(ct));
/// Get a price list item detail by id.
[HttpGet("price-list-items/{id:int}")]
public async Task PriceListItemDetail(int id, CancellationToken ct)
=> Ok(await _service.PriceListItemDetailAsync(id, ct));
/// Create a new price list item.
[HttpPost("price-list-items")]
public async Task CreatePriceListItem([FromBody] PriceListItemPostModel model, CancellationToken ct)
=> Ok(await _service.CreatePriceListItemAsync(model, ct));
/// Update an existing price list item (the model id identifies the item).
[HttpPatch("price-list-items")]
public async Task UpdatePriceListItem([FromBody] PriceListItemPatchModel model, CancellationToken ct)
=> Ok(await _service.UpdatePriceListItemAsync(model, ct));
// ---- Stock movements ----
/// List stock movements (paged).
[HttpGet("stock-movements")]
public async Task ListStockMovements(int page = 1, int pageSize = 20, CancellationToken ct = default)
=> Ok(await _service.ListStockMovementsAsync(page, pageSize, ct));
/// Get a pre-filled default stock movement model for the given price list item id.
[HttpGet("stock-movements/default/{priceListItemId:int}")]
public async Task StockMovementDefault(int priceListItemId, CancellationToken ct)
=> Ok(await _service.StockMovementDefaultAsync(priceListItemId, ct));
/// Get a stock movement detail by id.
[HttpGet("stock-movements/{id:int}")]
public async Task StockMovementDetail(int id, CancellationToken ct)
=> Ok(await _service.StockMovementDetailAsync(id, ct));
/// Create a new stock movement.
[HttpPost("stock-movements")]
public async Task CreateStockMovement([FromBody] StockMovementPostModel model, CancellationToken ct)
=> Ok(await _service.CreateStockMovementAsync(model, ct));
/// Update an existing stock movement (the model id identifies the movement).
[HttpPatch("stock-movements")]
public async Task UpdateStockMovement([FromBody] StockMovementPatchModel model, CancellationToken ct)
=> Ok(await _service.UpdateStockMovementAsync(model, ct));
/// Delete a stock movement by id.
[HttpDelete("stock-movements/{id:int}")]
public async Task DeleteStockMovement(int id, CancellationToken ct)
=> Ok(await _service.DeleteStockMovementAsync(id, ct));
// ---- Tags ----
/// List tags (paged).
[HttpGet("tags")]
public async Task ListTags(int page = 1, int pageSize = 20, CancellationToken ct = default)
=> Ok(await _service.ListTagsAsync(page, pageSize, ct));
/// Create a new tag.
[HttpPost("tags")]
public async Task CreateTag([FromBody] TagPostModel model, CancellationToken ct)
=> Ok(await _service.CreateTagAsync(model, ct));
/// Update an existing tag (the model id identifies the tag).
[HttpPatch("tags")]
public async Task UpdateTag([FromBody] TagPatchModel model, CancellationToken ct)
=> Ok(await _service.UpdateTagAsync(model, ct));
/// Delete a tag by id.
[HttpDelete("tags/{id:int}")]
public async Task DeleteTag(int id, CancellationToken ct)
=> Ok(await _service.DeleteTagAsync(id, ct));
}