// This is for Object ID for all the things in our database.
import DatabaseProperty from "./Database/DatabaseProperty";
import BadDataException from "./Exception/BadDataException";
import { ObjectType } from "./JSON";
export default class Decimal extends DatabaseProperty {
    get value() {
        return this._value;
    }
    set value(v) {
        this._value = v;
    }
    constructor(value) {
        super();
        this._value = 0;
        if (typeof value === "string") {
            value = parseFloat(value);
        }
        if (value instanceof Decimal) {
            value = value.value;
        }
        this.value = value;
    }
    equals(other) {
        return this.value.toString() === other.value.toString();
    }
    toString() {
        return this.value.toString();
    }
    static toDatabase(value) {
        if (value) {
            if (typeof value === "string") {
                value = new Decimal(value);
            }
            return value.toString();
        }
        return null;
    }
    toJSON() {
        return {
            _type: ObjectType.Decimal,
            value: this.toString(),
        };
    }
    static fromJSON(json) {
        if (json["_type"] === ObjectType.Decimal) {
            return new Decimal(json["value"] || 0);
        }
        throw new BadDataException("Invalid JSON: " + JSON.stringify(json));
    }
    static fromDatabase(_value) {
        if (_value) {
            return new Decimal(_value);
        }
        return null;
    }
    static fromString(value) {
        return new Decimal(value);
    }
}
//# sourceMappingURL=Decimal.js.map