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

/**
 * Resource for creating a new remission return.
 * It uses the RemissionReturnReceiptService to handle the creation logic.
 * @param {Function} params - Function that returns parameters for creating a return
 * @return {Resource} Angular resource that manages the return creation data
 */
export const createReturnResource = (params: () => FetchReturn) => {
  const remissionReturnReceiptService = inject(RemissionReturnReceiptService);
  return resource({
    params,
    loader: ({ abortSignal, params }) =>
      remissionReturnReceiptService.fetchReturn(params, abortSignal),
  });
};
