using DoliMiddlewareApi.Dtos.Dolibarr.Setup;
using DoliMiddlewareApi.Dtos.query.Setup;
using DoliMiddlewareApi.Mappers;
using DoliMiddlewareApi.Services.Clients;

namespace DoliMiddlewareApi.Services;

public class SetupService(IDolibarrApiClient apiClient)
{
    public async Task<List<PaymentTypeDto>> GetPaymentTypesAsync()
    {
        var data = await apiClient.GetCollectionAsync<PaymentTypeResponse>("setup/dictionary/payment_types");
        return data.Select(SetupMapper.MapToPaymentTypeDto).ToList();
    }

    public async Task<List<CountryDto>> GetCountriesAsync()
    {
        var data = await apiClient.GetCollectionAsync<CountryResponse>("setup/dictionary/countries");
        return data.Select(SetupMapper.MapToCountryDto).ToList();
    }

    public async Task<List<CivilityDto>> GetCivilitiesAsync()
    {
        var data = await apiClient.GetCollectionAsync<CivilityResponse>("setup/dictionary/civilities");
        return data.Select(SetupMapper.MapToCivilityDto).ToList();
    }

    public async Task<List<ContactTypeDto>> GetContactTypesAsync()
    {
        var data = await apiClient.GetCollectionAsync<ContactTypeResponse>("setup/dictionary/contact_types");
        return data.Select(SetupMapper.MapToContactTypeDto).ToList();
    }

    public async Task<List<PaymentTermDto>> GetPaymentTermsAsync()
    {
        var data = await apiClient.GetCollectionAsync<PaymentTermResponse>("setup/dictionary/payment_terms");
        return data.Select(SetupMapper.MapToPaymentTermDto).ToList();
    }

    public async Task<CompanyDto> GetCompanyAsync()
    {
        var data = await apiClient.GetResourceAsync<CompanyResponse>("setup/company");
        return SetupMapper.MapToCompanyDto(data);
    }
}