using CommunityToolkit.Mvvm.DependencyInjection;
using FastBill.Models;
using PSCHelpdesk.Shared.Service;
using PSCHelpdesk.Shared.Setting;

namespace FastBill.Services;

public class CustomerService
{
    private readonly SettingsManager? _settingsManager;
    private readonly Api.Customers _customerApi;
    private readonly Api.Contacts _contactApi;

    public CustomerService()
    {
        _settingsManager = (SettingsManager)Ioc.Default.GetService<ISettingsManager>();
        _customerApi = new Api.Customers();
        _contactApi = new Api.Contacts();
    }

    public async Task<List<Customer>> SearchCustomer(string term)
    {
        var settings = new Settings();
        _settingsManager.LoadPluginSettings("FastbillSettings", settings);
        
        List<Customer> customers = new List<Customer>();
        customers = await _customerApi.SearchCustomer(settings, term);
        return customers;
    }

    public async Task<List<Contact>> GetContacts(string customerId)
    {
        var settings = new Settings();
        _settingsManager.LoadPluginSettings("FastbillSettings", settings);
        
        List<Contact> contacts = new List<Contact>();
        contacts = await _contactApi.GetContacts(settings, customerId);
        return contacts;
    }
}