import { resource, inject } from '@angular/core';
import { RemissionSupplierService } from '@isa/remission/data-access';

/**
 * Creates an Angular resource for fetching supplier data.
 * The resource automatically loads all suppliers for the assigned stock.
 * Results are cached for performance.
 * 
 * @function createSupplierResource
 * @returns {Resource} Angular resource that manages supplier data
 * 
 * @example
 * const supplierResource = createSupplierResource();
 * 
 * // Access the suppliers
 * const suppliers = supplierResource.value();
 * const isLoading = supplierResource.isLoading();
 * 
 * // Find a specific supplier
 * const supplier = suppliers?.find(s => s.id === supplierId);
 */
export const createSupplierResource = () => {
  const remissionSupplierService = inject(RemissionSupplierService);
  return resource({
    loader: ({ abortSignal }) =>
      remissionSupplierService.fetchSuppliers(abortSignal),
  });
};
