import { Injectable } from '@angular/core';
import { Mapper } from './mapper';
import { Product } from '../models/product';
import { PriceDTO } from '@swagger/remi';

@Injectable()
export class ProductToPriceDTOMapping implements Mapper<Product, PriceDTO> {
  defaultPrice: PriceDTO = {
    value: { value: 0, currency: 'EUR' },
  };

  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');
    }
  }
}
