using Microsoft.AspNetCore.Mvc;
using Idoklad.Services;

namespace Idoklad.Controllers;

/// <summary>
/// Read-only iDoklad code lists / registers. Requires iDoklad credentials (headers or environment
/// defaults).
/// </summary>
[ApiController]
[Produces("application/json")]
[Tags("CodeLists")]
public sealed class CodeListsController : ControllerBase
{
    private readonly CodeListsService _service;

    public CodeListsController(CodeListsService service) => _service = service;

    /// <summary>List banks (paged).</summary>
    [HttpGet("code-lists/banks")]
    public async Task<IActionResult> Banks(int page = 1, int pageSize = 20, CancellationToken ct = default)
        => Ok(await _service.ListBanksAsync(page, pageSize, ct));

    /// <summary>Get a bank detail by id.</summary>
    [HttpGet("code-lists/banks/{id:int}")]
    public async Task<IActionResult> BankDetail(int id, CancellationToken ct)
        => Ok(await _service.BankDetailAsync(id, ct));

    /// <summary>List countries (paged).</summary>
    [HttpGet("code-lists/countries")]
    public async Task<IActionResult> Countries(int page = 1, int pageSize = 20, CancellationToken ct = default)
        => Ok(await _service.ListCountriesAsync(page, pageSize, ct));

    /// <summary>Get a country detail by id.</summary>
    [HttpGet("code-lists/countries/{id:int}")]
    public async Task<IActionResult> CountryDetail(int id, CancellationToken ct)
        => Ok(await _service.CountryDetailAsync(id, ct));

    /// <summary>List currencies (paged).</summary>
    [HttpGet("code-lists/currencies")]
    public async Task<IActionResult> Currencies(int page = 1, int pageSize = 20, CancellationToken ct = default)
        => Ok(await _service.ListCurrenciesAsync(page, pageSize, ct));

    /// <summary>Get a currency detail by id.</summary>
    [HttpGet("code-lists/currencies/{id:int}")]
    public async Task<IActionResult> CurrencyDetail(int id, CancellationToken ct)
        => Ok(await _service.CurrencyDetailAsync(id, ct));

    /// <summary>List constant symbols (paged).</summary>
    [HttpGet("code-lists/constant-symbols")]
    public async Task<IActionResult> ConstantSymbols(int page = 1, int pageSize = 20, CancellationToken ct = default)
        => Ok(await _service.ListConstantSymbolsAsync(page, pageSize, ct));

    /// <summary>Get a constant symbol detail by id.</summary>
    [HttpGet("code-lists/constant-symbols/{id:int}")]
    public async Task<IActionResult> ConstantSymbolDetail(int id, CancellationToken ct)
        => Ok(await _service.ConstantSymbolDetailAsync(id, ct));

    /// <summary>List exchange rates (paged).</summary>
    [HttpGet("code-lists/exchange-rates")]
    public async Task<IActionResult> ExchangeRates(int page = 1, int pageSize = 20, CancellationToken ct = default)
        => Ok(await _service.ListExchangeRatesAsync(page, pageSize, ct));

    /// <summary>Get an exchange rate detail by id.</summary>
    [HttpGet("code-lists/exchange-rates/{id:int}")]
    public async Task<IActionResult> ExchangeRateDetail(int id, CancellationToken ct)
        => Ok(await _service.ExchangeRateDetailAsync(id, ct));

    /// <summary>List payment options (paged).</summary>
    [HttpGet("code-lists/payment-options")]
    public async Task<IActionResult> PaymentOptions(int page = 1, int pageSize = 20, CancellationToken ct = default)
        => Ok(await _service.ListPaymentOptionsAsync(page, pageSize, ct));

    /// <summary>Get a payment option detail by id.</summary>
    [HttpGet("code-lists/payment-options/{id:int}")]
    public async Task<IActionResult> PaymentOptionDetail(int id, CancellationToken ct)
        => Ok(await _service.PaymentOptionDetailAsync(id, ct));

    /// <summary>List VAT codes (paged).</summary>
    [HttpGet("code-lists/vat-codes")]
    public async Task<IActionResult> VatCodes(int page = 1, int pageSize = 20, CancellationToken ct = default)
        => Ok(await _service.ListVatCodesAsync(page, pageSize, ct));

    /// <summary>Get a VAT code detail by id.</summary>
    [HttpGet("code-lists/vat-codes/{id:int}")]
    public async Task<IActionResult> VatCodeDetail(int id, CancellationToken ct)
        => Ok(await _service.VatCodeDetailAsync(id, ct));

    /// <summary>List VAT reverse-charge codes (paged).</summary>
    [HttpGet("code-lists/vat-reverse-charge-codes")]
    public async Task<IActionResult> VatReverseChargeCodes(int page = 1, int pageSize = 20, CancellationToken ct = default)
        => Ok(await _service.ListVatReverseChargeCodesAsync(page, pageSize, ct));

    /// <summary>Get a VAT reverse-charge code detail by id.</summary>
    [HttpGet("code-lists/vat-reverse-charge-codes/{id:int}")]
    public async Task<IActionResult> VatReverseChargeCodeDetail(int id, CancellationToken ct)
        => Ok(await _service.VatReverseChargeCodeDetailAsync(id, ct));

    /// <summary>List sales offices (paged).</summary>
    [HttpGet("code-lists/sales-offices")]
    public async Task<IActionResult> SalesOffices(int page = 1, int pageSize = 20, CancellationToken ct = default)
        => Ok(await _service.ListSalesOfficesAsync(page, pageSize, ct));

    /// <summary>Get a sales office detail by id.</summary>
    [HttpGet("code-lists/sales-offices/{id:int}")]
    public async Task<IActionResult> SalesOfficeDetail(int id, CancellationToken ct)
        => Ok(await _service.SalesOfficeDetailAsync(id, ct));

    /// <summary>List sales POS equipment (paged).</summary>
    [HttpGet("code-lists/sales-pos-equipment")]
    public async Task<IActionResult> SalesPosEquipment(int page = 1, int pageSize = 20, CancellationToken ct = default)
        => Ok(await _service.ListSalesPosEquipmentAsync(page, pageSize, ct));

    /// <summary>Get a sales POS equipment detail by id.</summary>
    [HttpGet("code-lists/sales-pos-equipment/{id:int}")]
    public async Task<IActionResult> SalesPosEquipmentDetail(int id, CancellationToken ct)
        => Ok(await _service.SalesPosEquipmentDetailAsync(id, ct));
}
