import AccountRights from "./AccountRights.js";
import AccountStatus from "./AccountStatus.js";

export default class AccountInfo {

    /**
     * @type {AccountRights}
     */
    #accountRights = new AccountRights();

    /**
     * @type {string} account status
     */
    #status = AccountStatus.NORMAL;

    /**
     * @type {number}
     */
    #updateTime = Date.now();

    /**
     * @type {Map<string, number>}
     */
    #balances = new Map();

    constructor() {
        //super();
        this.#updateTime = Date.now();
    }

    /**
     * Returns if this account is allowed to trade
     * @returns {boolean} is allowed to trade
     */
    isAllowedToTrade() {
        return this.#accountRights.canTrade;
    }

    /**
     * Returns if this account is allowed to withdraw money
     * @returns {boolean} is allowed to withdraw money
     */
    isAllowedToWithdraw() {
        return this.#accountRights.canWithdraw;
    }

    /**
     * Returns if this account is allowed to deposit
     * @returns {boolean} is allowed to deposit
     */
    isAllowedToDeposit() {
        return this.#accountRights.canDeposit;
    }

    /**
     * Timestamp of last update of this object
     * @returns {number}  update timestmap
     */
    getLastUpdateTime() {
        return this.#updateTime;
    }

    /**
     * Map with all balances of this account.
     * Zero balances are filtered out and not displayed here
     * @returns {Map<string, number>} map with balances
     */
    getBalances() {
        return this.#balances;
    }

    /**
     * @returns {string}
     */
    getStatus() {
        return this.#status;
    }

    /**
     * @param {string} status 
     */
    setStatus(status) {
        this.#status = status;
    }

    /**
     * @param {AccountInformation} accountInfo 
     */
    update(accountInfo) {
        // TODO
        /*if (accountInfo == null) {
            return;
        }

        this.#updateTime = accountInfo.updateTime;
        this.#canDeposit = accountInfo.canDeposit;
        this.#canTrade = accountInfo.canTrade;
        this.#canWithdraw = accountInfo.canWithdraw;

        for (let balance of accountInfo.balances) {
            if (balance.free > 0) {
                this.#balances.set(balance.asset, balance.free);
            }
        }*/
    }
}