import { Injectable, Injector } from '@angular/core';
import { Mapper } from './mapper';

@Injectable({ providedIn: 'root' })
export class MappingService {
  constructor(private injector: Injector) {}

  get<T extends Mapper>(sourceName: string, targetName: string): T {
    const mappers = (this.injector.get(Mapper) as unknown) as Mapper[];
    return mappers.find((f) => f.sourceName === sourceName && f.targetName === targetName) as T;
  }
}
