{"size": 1473, "ext": "js", "max_stars_repo_path": "src/client/src/ui/spotTile/model/notifications.js", "max_stars_repo_name": "vasipuica/ReactiveTraderCloud", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/client/src/ui/spotTile/model/notifications.js", "max_issues_repo_name": "vasipuica/ReactiveTraderCloud", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/client/src/ui/spotTile/model/notifications.js", "max_forks_repo_name": "vasipuica/ReactiveTraderCloud", "max_forks_repo_forks_event_min_datetime": "2021-06-12T07:32:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-12T07:32:16.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 24.1475409836, "max_line_length": 84, "alphanum_fraction": 0.6782077393}
import { utils } from '../../../system';
import { Trade, Direction } from '../../../services/model';
import { NotificationType  } from './';
import numeral from 'numeral';

export class NotificationBase {
  constructor(notificationType) {
    this.notificationType = notificationType;
  }
}

export class TextNotification extends NotificationBase {
  constructor(message) {
    super(NotificationType.Text);
    this.message = message;
  }
}

export class TradeExecutionNotification extends NotificationBase {
  direction;
  notional;
  status;
  dealtCurrency;
  termsCurrency;
  spotRate;
  formattedValueDate;
  tradeId;
  error;

  constructor(trade, error) {
    super(NotificationType.Trade);
    this.error = error;
    if (trade) {
      this.direction = trade.direction === Direction.Sell
        ? 'Sold'
        : 'Bought';
      this.notional = numeral(trade.notional).format('0,000,000[.]00');
      this.status = trade.status;
      this.dealtCurrency = trade.currencyPair.base;
      this.termsCurrency = trade.currencyPair.terms;
      this.spotRate = trade.spotRate;
      this.formattedValueDate = `SP. ${utils.formatDate(trade.valueDate, '%b %e')}`;
      this.tradeId = trade.tradeId;
    }
  }

  static createForSuccess(trade) {
    return new TradeExecutionNotification(trade);
  }

  static createForError(error) {
    return new TradeExecutionNotification(null, error);
  }

  get hasError() {
    return typeof this.error !== 'undefined';
  }
}


