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

namespace Idoklad.Services;

/// <summary>Issued (outgoing) invoices agenda.</summary>
public sealed class IssuedInvoicesService
{
    private readonly IdokladApiAccessor _accessor;

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

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

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

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

    public async Task<IssuedInvoiceGetModel> CreateAsync(IssuedInvoicePostModel model, CancellationToken ct)
        => (await _accessor.Api.IssuedInvoiceClient.PostAsync(model, ct)).Unwrap();

    public async Task<IssuedInvoiceGetModel> UpdateAsync(IssuedInvoicePatchModel model, CancellationToken ct)
        => (await _accessor.Api.IssuedInvoiceClient.UpdateAsync(model, ct)).Unwrap();

    public async Task<IssuedInvoiceCopyGetModel> CopyAsync(int id, CancellationToken ct)
        => (await _accessor.Api.IssuedInvoiceClient.CopyAsync(id, ct)).Unwrap();

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