"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EthereumStrikePositionPresenter = void 0;
const lodash_1 = require("lodash");
const presenter_template_decorator_1 = require("../../../app-toolkit/decorators/presenter-template.decorator");
const compound_position_presenter_1 = require("../../../apps/compound/common/compound.position-presenter");
const position_interface_1 = require("../../../position/position.interface");
let EthereumStrikePositionPresenter = class EthereumStrikePositionPresenter extends compound_position_presenter_1.CompoundPositionPresenter {
    constructor() {
        super(...arguments);
        this.explorePresentationConfig = {
            tabs: [
                {
                    label: 'Lending',
                    viewType: 'split',
                    views: [
                        {
                            viewType: 'list',
                            label: 'Supply',
                            groupIds: ['supply'],
                        },
                        {
                            viewType: 'list',
                            label: 'Borrow',
                            groupIds: ['borrow'],
                        },
                    ],
                },
            ],
        };
    }
    getHealthFactor(totalCollateralUSD, borrowPositionBalances) {
        const debt = borrowPositionBalances.filter(balance => balance.balanceUSD < 0);
        if (debt.length == 0)
            return 100;
        const totalDebtUSD = (0, lodash_1.sumBy)(debt, a => a.balanceUSD);
        const healthFactorsRatio = debt.map(balance => {
            const healthFactor = (totalCollateralUSD * balance.dataProps.collateralFactor) / Math.abs(balance.balanceUSD);
            const debtRatio = balance.balanceUSD / totalDebtUSD;
            return healthFactor * debtRatio;
        });
        return (0, lodash_1.sum)(healthFactorsRatio) / healthFactorsRatio.length;
    }
    metadataItemsForBalanceGroup(groupLabel, balances, _dataProps) {
        if (groupLabel === 'Lending') {
            const borrowPositionBalances = balances.filter((v) => (0, position_interface_1.isContractPosition)(v));
            const collaterals = balances.filter(balance => balance.balanceUSD > 0);
            const debt = balances.filter(balance => balance.balanceUSD < 0);
            const totalCollateralUSD = (0, lodash_1.sumBy)(collaterals, a => a.balanceUSD);
            const totalDebtUSD = (0, lodash_1.sumBy)(debt, a => a.balanceUSD);
            const utilRatio = (Math.abs(totalDebtUSD) / totalCollateralUSD) * 100;
            const healthFactor = this.getHealthFactor(totalCollateralUSD, borrowPositionBalances);
            return [
                {
                    label: 'Collateral',
                    value: totalCollateralUSD,
                    type: 'dollar',
                },
                {
                    label: 'Debt',
                    value: totalDebtUSD,
                    type: 'dollar',
                },
                {
                    label: 'Utilization Rate',
                    value: utilRatio,
                    type: 'pct',
                },
                {
                    label: 'Health Factor',
                    value: healthFactor,
                    type: 'number',
                },
            ];
        }
        return [];
    }
};
EthereumStrikePositionPresenter = __decorate([
    (0, presenter_template_decorator_1.PresenterTemplate)()
], EthereumStrikePositionPresenter);
exports.EthereumStrikePositionPresenter = EthereumStrikePositionPresenter;
//# sourceMappingURL=strike.position-presenter.js.map