using IdokladSdk.Models.CashRegister;
using IdokladSdk.Models.CashVoucher;
using IdokladSdk.Models.ReceivedReceipt.Patch;
using IdokladSdk.Models.ReceivedReceipt.Post;
using Microsoft.AspNetCore.Mvc;
using Idoklad.Services;
namespace Idoklad.Controllers;
///
/// Received receipts and cash agendas. Requires iDoklad credentials (headers or environment defaults).
///
[ApiController]
[Produces("application/json")]
[Tags("PurchaseAndCash")]
public sealed class PurchaseCashController : ControllerBase
{
private readonly PurchaseCashService _service;
public PurchaseCashController(PurchaseCashService service) => _service = service;
// ---- Received receipts ----
/// List received receipts (paged).
[HttpGet("received-receipts")]
public async Task ListReceivedReceipts(int page = 1, int pageSize = 20, CancellationToken ct = default)
=> Ok(await _service.ListReceivedReceiptsAsync(page, pageSize, ct));
/// Get a pre-filled default model for creating a new received receipt.
[HttpGet("received-receipts/default")]
public async Task ReceivedReceiptDefault(CancellationToken ct)
=> Ok(await _service.ReceivedReceiptDefaultAsync(ct));
/// Get a received receipt detail by id.
[HttpGet("received-receipts/{id:int}")]
public async Task ReceivedReceiptDetail(int id, CancellationToken ct)
=> Ok(await _service.ReceivedReceiptDetailAsync(id, ct));
/// Create a new received receipt.
[HttpPost("received-receipts")]
public async Task CreateReceivedReceipt([FromBody] ReceivedReceiptPostModel model, CancellationToken ct)
=> Ok(await _service.CreateReceivedReceiptAsync(model, ct));
/// Update an existing received receipt (the model id identifies the document).
[HttpPatch("received-receipts")]
public async Task UpdateReceivedReceipt([FromBody] ReceivedReceiptPatchModel model, CancellationToken ct)
=> Ok(await _service.UpdateReceivedReceiptAsync(model, ct));
/// Delete a received receipt by id.
[HttpDelete("received-receipts/{id:int}")]
public async Task DeleteReceivedReceipt(int id, CancellationToken ct)
=> Ok(await _service.DeleteReceivedReceiptAsync(id, ct));
// ---- Cash vouchers ----
/// List cash vouchers (paged).
[HttpGet("cash-vouchers")]
public async Task ListCashVouchers(int page = 1, int pageSize = 20, CancellationToken ct = default)
=> Ok(await _service.ListCashVouchersAsync(page, pageSize, ct));
/// Get a cash voucher detail by id.
[HttpGet("cash-vouchers/{id:int}")]
public async Task CashVoucherDetail(int id, CancellationToken ct)
=> Ok(await _service.CashVoucherDetailAsync(id, ct));
/// Create a new cash voucher.
[HttpPost("cash-vouchers")]
public async Task CreateCashVoucher([FromBody] CashVoucherPostModel model, CancellationToken ct)
=> Ok(await _service.CreateCashVoucherAsync(model, ct));
/// Update an existing cash voucher (the model id identifies the document).
[HttpPatch("cash-vouchers")]
public async Task UpdateCashVoucher([FromBody] CashVoucherPatchModel model, CancellationToken ct)
=> Ok(await _service.UpdateCashVoucherAsync(model, ct));
/// Delete a cash voucher by id.
[HttpDelete("cash-vouchers/{id:int}")]
public async Task DeleteCashVoucher(int id, CancellationToken ct)
=> Ok(await _service.DeleteCashVoucherAsync(id, ct));
// ---- Cash registers ----
/// List cash registers (paged).
[HttpGet("cash-registers")]
public async Task ListCashRegisters(int page = 1, int pageSize = 20, CancellationToken ct = default)
=> Ok(await _service.ListCashRegistersAsync(page, pageSize, ct));
/// Get a cash register detail by id.
[HttpGet("cash-registers/{id:int}")]
public async Task CashRegisterDetail(int id, CancellationToken ct)
=> Ok(await _service.CashRegisterDetailAsync(id, ct));
/// Create a new cash register.
[HttpPost("cash-registers")]
public async Task CreateCashRegister([FromBody] CashRegisterPostModel model, CancellationToken ct)
=> Ok(await _service.CreateCashRegisterAsync(model, ct));
/// Update an existing cash register (the model id identifies the register).
[HttpPatch("cash-registers")]
public async Task UpdateCashRegister([FromBody] CashRegisterPatchModel model, CancellationToken ct)
=> Ok(await _service.UpdateCashRegisterAsync(model, ct));
/// Delete a cash register by id.
[HttpDelete("cash-registers/{id:int}")]
public async Task DeleteCashRegister(int id, CancellationToken ct)
=> Ok(await _service.DeleteCashRegisterAsync(id, ct));
}