using IdokladSdk.Models.ReceivedInvoice;
using IdokladSdk.Response;
using Idoklad.Client;

namespace Idoklad.Services;

/// <summary>Received (incoming) invoices agenda.</summary>
public sealed class ReceivedInvoicesService
{
    private readonly IdokladApiAccessor _accessor;

    public ReceivedInvoicesService(IdokladApiAccessor accessor) => _accessor = accessor;

    public async Task<Page<ReceivedInvoiceListGetModel>> ListAsync(int page, int pageSize, CancellationToken ct)
        => (await _accessor.Api.ReceivedInvoiceClient.List().Page(page).PageSize(pageSize).GetAsync(ct)).Unwrap();

    public async Task<ReceivedInvoiceGetModel> DetailAsync(int id, CancellationToken ct)
        => (await _accessor.Api.ReceivedInvoiceClient.Detail(id).GetAsync(ct)).Unwrap();

    public async Task<ReceivedInvoiceDefaultGetModel> DefaultAsync(CancellationToken ct)
        => (await _accessor.Api.ReceivedInvoiceClient.DefaultAsync(ct)).Unwrap();

    public async Task<ReceivedInvoiceGetModel> CreateAsync(ReceivedInvoicePostModel model, CancellationToken ct)
        => (await _accessor.Api.ReceivedInvoiceClient.PostAsync(model, ct)).Unwrap();

    public async Task<ReceivedInvoiceGetModel> UpdateAsync(ReceivedInvoicePatchModel model, CancellationToken ct)
        => (await _accessor.Api.ReceivedInvoiceClient.UpdateAsync(model, ct)).Unwrap();

    public async Task<bool> DeleteAsync(int id, CancellationToken ct)
        => (await _accessor.Api.ReceivedInvoiceClient.DeleteAsync(id, ct)).Unwrap();
}
