using IdokladSdk.Models.BankAccount;
using Microsoft.AspNetCore.Mvc;
using Idoklad.Services;
namespace Idoklad.Controllers;
///
/// Supporting registers: bank accounts, VAT rates and numeric sequences. Requires iDoklad
/// credentials (headers or environment defaults).
///
[ApiController]
[Route("registers")]
[Produces("application/json")]
[Tags("Registers")]
public sealed class RegistersController : ControllerBase
{
private readonly RegistersService _service;
public RegistersController(RegistersService service) => _service = service;
// ---- Bank accounts ----
/// List bank accounts (paged, optionally filtered and sorted).
[HttpGet("bank-accounts")]
public async Task ListBankAccounts(
[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.ListBankAccountsAsync(page, pageSize, filter, filtertype, sort, ct));
/// Get a bank account detail by id.
[HttpGet("bank-accounts/{id:int}")]
public async Task BankAccountDetail(int id, CancellationToken ct)
=> Ok(await _service.BankAccountDetailAsync(id, ct));
/// Create a new bank account.
[HttpPost("bank-accounts")]
public async Task CreateBankAccount([FromBody] BankAccountPostModel model, CancellationToken ct)
=> Ok(await _service.CreateBankAccountAsync(model, ct));
/// Update an existing bank account (the model id identifies the account).
[HttpPatch("bank-accounts")]
public async Task UpdateBankAccount([FromBody] BankAccountPatchModel model, CancellationToken ct)
=> Ok(await _service.UpdateBankAccountAsync(model, ct));
/// Delete a bank account by id.
[HttpDelete("bank-accounts/{id:int}")]
public async Task DeleteBankAccount(int id, CancellationToken ct)
=> Ok(await _service.DeleteBankAccountAsync(id, ct));
// ---- VAT rates (read-only) ----
/// List VAT rates (paged, optionally filtered and sorted).
[HttpGet("vat-rates")]
public async Task ListVatRates(
[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.ListVatRatesAsync(page, pageSize, filter, filtertype, sort, ct));
/// Get a VAT rate detail by id.
[HttpGet("vat-rates/{id:int}")]
public async Task VatRateDetail(int id, CancellationToken ct)
=> Ok(await _service.VatRateDetailAsync(id, ct));
// ---- Numeric sequences (read-only) ----
/// List numeric (document) sequences (paged, optionally filtered and sorted).
[HttpGet("numeric-sequences")]
public async Task ListNumericSequences(
[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.ListNumericSequencesAsync(page, pageSize, filter, filtertype, sort, ct));
}