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

namespace Idoklad.Services;

/// <summary>Contacts (customers/suppliers) agenda.</summary>
public sealed class ContactsService
{
    private readonly IdokladApiAccessor _accessor;

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

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

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

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

    public async Task<ContactGetModel> CreateAsync(ContactPostModel model, CancellationToken ct)
        => (await _accessor.Api.ContactClient.PostAsync(model, ct)).Unwrap();

    public async Task<ContactGetModel> UpdateAsync(ContactPatchModel model, CancellationToken ct)
        => (await _accessor.Api.ContactClient.UpdateAsync(model, ct)).Unwrap();

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