"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Used to convert between satoshi and bitcoin.
const ConversionFactor = 100000000;
class Amount {
    constructor(satoshis) {
        this._satoshis = satoshis;
        this.toJSON = Amount.prototype.toJSON;
        this.GetSatoshiAmount = Amount.prototype.GetSatoshiAmount;
    }
    // Create an Amount object using bitcoin unit.
    static FromBitcoin(bitcoin) {
        return new Amount(bitcoin * ConversionFactor);
    }
    // Create an Amount object using satoshi unit.
    static FromSatoshis(satoshis) {
        return new Amount(satoshis);
    }
    // Get the amount value in bitcoin.
    GetBitcoinAmount() {
        return this._satoshis / ConversionFactor;
    }
    // Get the amount value in satoshi.
    GetSatoshiAmount() {
        return this._satoshis;
    }
    // Return a new Amount object with value increased by the given amount of
    // satoshi.
    AddSatoshis(satoshis) {
        return new Amount(this._satoshis + satoshis);
    }
    // Return a new Amount object with value increased by the given amount of
    // bitcoin.
    AddBitcoins(bitcoins) {
        return new Amount(this._satoshis + bitcoins * ConversionFactor);
    }
    // Return a new Amount object with value increased by the given amount.
    AddAmount(amount) {
        return new Amount(this._satoshis + amount._satoshis);
    }
    // Returns the difference between the amount of satoshi in this object and
    // the amount of satoshi of the given object.
    CompareWith(amount) {
        return new Amount(this._satoshis - amount._satoshis);
    }
    toJSON() {
        return Object.assign({}, this, {
            _satoshis: this._satoshis,
        });
    }
    static fromJSON(json) {
        if (!json) {
            return Amount.FromSatoshis(0);
        }
        const amount = Object.create(Amount.prototype);
        return Object.assign(amount, json, {
            _satoshis: json._satoshis,
            GetSatoshiAmount: Amount.prototype.GetSatoshiAmount,
        });
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    static reviver(key, value) {
        return key === '' ? Amount.fromJSON(value) : value;
    }
}
exports.default = Amount;
//# sourceMappingURL=Amount.js.map