import { Injectable } from '@angular/core';
import { PriceDTO } from '@cmf/inventory-api';
import { Mapper } from './mapper';
import { Product } from '../models/product';

@Injectable()
export class ProductToPriceDTOMapping implements Mapper<Product, PriceDTO> {
  defaultPrice: PriceDTO = null;

  constructor() {}

  get sourceName(): string {
    return 'Product';
  }

  get targetName(): string {
    return 'PriceDTO';
  }

  map(source: Product): PriceDTO {
    if (source.sourcePrice) {
      return source.sourcePrice;
    } else {
      return this.defaultPrice;
      throw Error('Keine Preisinformationen vorhanden');
    }
  }
}
