{"version":3,"sources":["../../src/structs/Money.ts"],"sourcesContent":["import { Struct, isEmpty, text, required } from '@thisisagile/easy';\nimport { Currency } from '../enums/Currency';\n\nexport class Money extends Struct {\n  @required() readonly currency = Currency.byId<Currency>(this.state.currency);\n  @required() readonly value = this.state.value as number;\n\n  add(amount: number): Money {\n    return money(this.currency, this.value + amount);\n  }\n  subtract(amount: number): Money {\n    return money(this.currency, this.value - amount);\n  }\n  times(n: number): Money {\n    return money(this.currency, this.value * n);\n  }\n\n  toString(): string {\n    return text(this.currency?.code)\n      .with(' ', this.value?.toFixed(this.currency?.digits ?? 2))\n      .toString();\n  }\n\n  static zero(currency: Currency): Money {\n    return Money.amount(currency);\n  }\n\n  static amount(currency: Currency, value: number = 0): Money {\n    return money(currency, value);\n  }\n}\n\nexport const money = (currency: Currency, value: number): Money => new Money({ currency: currency.id, value });\n\nexport const isMoney = (m?: unknown): m is Money => {\n  return !isEmpty(m) && m instanceof Money;\n};\n"],"mappings":";;;;;;;;AAAA,SAAS,QAAQ,SAAS,MAAM,gBAAgB;AAGzC,IAAM,SAAN,MAAM,eAAc,OAAO;AAAA,EACX,WAAW,SAAS,KAAe,KAAK,MAAM,QAAQ;AAAA,EACtD,QAAQ,KAAK,MAAM;AAAA,EAExC,IAAI,QAAuB;AACzB,WAAO,MAAM,KAAK,UAAU,KAAK,QAAQ,MAAM;AAAA,EACjD;AAAA,EACA,SAAS,QAAuB;AAC9B,WAAO,MAAM,KAAK,UAAU,KAAK,QAAQ,MAAM;AAAA,EACjD;AAAA,EACA,MAAM,GAAkB;AACtB,WAAO,MAAM,KAAK,UAAU,KAAK,QAAQ,CAAC;AAAA,EAC5C;AAAA,EAEA,WAAmB;AACjB,WAAO,KAAK,KAAK,UAAU,IAAI,EAC5B,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,UAAU,UAAU,CAAC,CAAC,EACzD,SAAS;AAAA,EACd;AAAA,EAEA,OAAO,KAAK,UAA2B;AACrC,WAAO,OAAM,OAAO,QAAQ;AAAA,EAC9B;AAAA,EAEA,OAAO,OAAO,UAAoB,QAAgB,GAAU;AAC1D,WAAO,MAAM,UAAU,KAAK;AAAA,EAC9B;AACF;AA1BuB;AAAA,EAApB,SAAS;AAAA,GADC,OACU;AACA;AAAA,EAApB,SAAS;AAAA,GAFC,OAEU;AAFhB,IAAM,QAAN;AA6BA,IAAM,QAAQ,CAAC,UAAoB,UAAyB,IAAI,MAAM,EAAE,UAAU,SAAS,IAAI,MAAM,CAAC;AAEtG,IAAM,UAAU,CAAC,MAA4B;AAClD,SAAO,CAAC,QAAQ,CAAC,KAAK,aAAa;AACrC;","names":[]}