import Serializable from "../../util/Serializable.js";

export default class Asset extends Serializable {
    #symbol = "";
    #market = "";

    constructor(symbol, market) {
        super();
        this.#symbol = symbol;
        this.#market = market;
    }

    /**
     * @returns {string} asset symbol ('BTC', 'ETH', ...)
     */
    getSymbol() {
        return this.#symbol;
    }

    /**
     * @returns {string} market type
     * @see MarketType
     */
    getMarket() {
        return this.#market;
    }

    /**
     * @returns {string} string representation of this object
     */
    toJson() {
        const obj = JSON.parse(super.toJson());
        obj.symbol = this.#symbol;
        obj.market = this.#market;
        
        return JSON.stringify(obj);
    }

    /**
     * @param {string} objString 
     * @returns {Asset}
     */
    static fromJson(objString) {
        const obj = JSON.parse(objString);

        return new Asset(obj.symbol, obj.market);
    }
}