package org.jetbrains.mps.samples.money.runtime;

/*Generated by MPS */

import java.math.BigDecimal;
import jetbrains.mps.references.Reference;

public class Money {
  private BigDecimal myAmount;
  public BigDecimal getAmount() {
    return this.myAmount;
  }
  private void _setAmount(BigDecimal value) {
    this.myAmount = value;
  }
  private BigDecimal setAmount(BigDecimal value) {
    _setAmount(value);
    return value;
  }
  private Reference<BigDecimal> refToAmount() {
    return new Reference<BigDecimal>() {
      public BigDecimal get() {
        return getAmount();
      }
      public void set(BigDecimal value) {
        _setAmount(value);
      }
    };
  }
  private String myCurrency;
  public String getCurrency() {
    return this.myCurrency;
  }
  private void _setCurrency(String value) {
    this.myCurrency = value;
  }
  private String setCurrency(String value) {
    _setCurrency(value);
    return value;
  }
  private Reference<String> refToCurrency() {
    return new Reference<String>() {
      public String get() {
        return getCurrency();
      }
      public void set(String value) {
        _setCurrency(value);
      }
    };
  }
  public Money(BigDecimal amount, String currency) {
    this.setAmount(amount);
    this.setCurrency(currency);
  }
  public Money(int amount, String currency) {
    this.setAmount(new BigDecimal(amount));
    this.setCurrency(currency);
  }
  public Money to(String targetCurrency) {
    return new Money(this.getAmount(), targetCurrency);
  }
  @Override
  public String toString() {
    return this.getAmount() + " " + this.getCurrency();
  }
  public Money plus(final Money other) {
    if (!(this.getCurrency().equals(other.getCurrency()))) {
      throw new IllegalArgumentException("The currencies do not match: " + this.getCurrency() + ":" + other.getCurrency());
    } else {
      return new Money(this.getAmount().add(other.getAmount()), this.getCurrency());
    }
  }
  public Money minus(final Money other) {
    if (!(this.getCurrency().equals(other.getCurrency()))) {
      throw new IllegalArgumentException("The currencies do not match: " + this.getCurrency() + ":" + other.getCurrency());
    } else {
      return new Money(this.getAmount().subtract(other.getAmount()), this.getCurrency());
    }
  }
}
