using IdokladSdk.Models.ReceivedInvoice;
using Microsoft.AspNetCore.Mvc;
using Idoklad.Services;
namespace Idoklad.Controllers;
///
/// Received (incoming) invoices agenda. Requires iDoklad credentials (headers or environment
/// defaults).
///
[ApiController]
[Route("received-invoices")]
[Produces("application/json")]
[Tags("ReceivedInvoices")]
public sealed class ReceivedInvoicesController : ControllerBase
{
private readonly ReceivedInvoicesService _service;
public ReceivedInvoicesController(ReceivedInvoicesService service) => _service = service;
///
/// List received invoices (paged, optionally filtered and sorted).
///
/// Optional iDoklad-style filter (see IssuedInvoices for the syntax).
/// How multiple conditions combine: and (default) or or.
/// Optional sort, e.g. DateOfReceiving~desc.
[HttpGet]
public async Task List(
[FromQuery] int page = 1,
[FromQuery] int pageSize = 20,
[FromQuery] string? filter = null,
[FromQuery] string? filtertype = null,
[FromQuery] string? sort = null,
CancellationToken ct = default)
=> Ok(await _service.ListAsync(page, pageSize, filter, filtertype, sort, ct));
/// Get a received invoice detail by id.
[HttpGet("{id:int}")]
public async Task Detail(int id, CancellationToken ct)
=> Ok(await _service.DetailAsync(id, ct));
/// Get a pre-filled default model for creating a new received invoice.
[HttpGet("default")]
public async Task Default(CancellationToken ct)
=> Ok(await _service.DefaultAsync(ct));
/// Create a new received invoice.
[HttpPost]
public async Task Create([FromBody] ReceivedInvoicePostModel model, CancellationToken ct)
=> Ok(await _service.CreateAsync(model, ct));
/// Update an existing received invoice (the model id identifies the invoice).
[HttpPatch]
public async Task Update([FromBody] ReceivedInvoicePatchModel model, CancellationToken ct)
=> Ok(await _service.UpdateAsync(model, ct));
/// Delete a received invoice by id.
[HttpDelete("{id:int}")]
public async Task Delete(int id, CancellationToken ct)
=> Ok(await _service.DeleteAsync(id, ct));
}