import 'package:money2/money2.dart';

import 'package:pshared/data/dto/money.dart';
import 'package:pshared/utils/money.dart';


extension MoneyMapper on Money {
  MoneyDTO toDTO() =>
      MoneyDTO(amount: toDecimal().toString(), currency: currency.isoCode);
}

extension MoneyDTOMapper on MoneyDTO {
  Money toDomain() {
    final parsed = parseMoneyWithCurrencyCode(amount, currency);
    if (parsed == null) {
      throw FormatException('Invalid money dto: $currency $amount');
    }
    return parsed;
  }
}
