using Domain.Entities;
using phronCare.UIBlazor.Services.Lookups;
using System.Net.Http.Json;

public class StockLookUpService: IStockLookUpService
{
    private readonly HttpClient _http;

    public StockLookUpService(HttpClient http)
    {
        _http = http;
    }

    public async Task<List<ELookUpItem>> GetProductDivisionsAsync(string filter = "")
    {
        string url = string.IsNullOrWhiteSpace(filter)
            ? "/api/LSMLookUp/productdivisions"
            : $"/api/LSMLookUp/productdivisions?q={Uri.EscapeDataString(filter)}";

        var result = await _http.GetFromJsonAsync<List<ELookUpItem>>(url);
        return result ?? new List<ELookUpItem>();
    }
    public async Task<List<ELookUpItem>> GetUnitsOfMeasureAsync(string filter = "")
    {
        var result = await _http.GetFromJsonAsync<List<ELookUpItem>>($"/api/LSMLookUp/units?q={filter}");
        return result ?? [];
    }
}
