import { Injectable } from '@angular/core';
import { Mapper } from './mapper';
import { RemissionProduct } from '../models/remission-product';
import { ReturnSuggestionDTO } from '@swagger/remi';

@Injectable()
export class ReturnSuggestionDtoToRemissionProductMapping implements Mapper<ReturnSuggestionDTO, RemissionProduct> {
  get sourceName(): string {
    return 'ReturnSuggestionDTO';
  }

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

  map(source: ReturnSuggestionDTO): RemissionProduct {
    return {
      id: source.id,
      department: source.department,
      imageId: source.product.ean,
      contributors: source.product.contributors,
      name: source.product.name,
      format: source.product.format,
      formatDetail: source.product.formatDetail,
      ean: source.product.ean,
      price: source.retailPrice.value.value,
      currency: source.retailPrice.value.currency,
      productGroup: source.product.productGroup,
      productGroupName: '',
      inStock: 0,
      remissionQuantity: source.returnItem && source.returnItem.data.predefinedReturnQuantity,
      remainingQuantity: source['remainingQuantityInStock'],
      placementType: source.placementType,
      remissionReason: source.returnReason,
      edition: source.product.volume,
      catalogProductNumber: source.product.catalogProductNumber,
      features: [],
      isResidual:
        !!source.impediment ||
        // tslint:disable-next-line: no-string-literal
        (source['descendantOf'] && !!source['descendantOf'].enabled),
      impediment: source.impediment?.comment !== 'Restmenge' ? source.impediment : undefined,
    } as RemissionProduct;
  }
}
