import { DerivativeFactory  } from '../lib/derivatives/DerivativeFactory';

/**
 * example for how to use factory to get OlympusFund data
 * @param address address
 */
async function getOlympusFundData(address: string) {

    const factory = DerivativeFactory.get();
    const service = await factory.getOlympusFund(address);
    const version = await service.getVersion();

    const [totalSupply, productStatus, fundType] = await Promise.all([
        service.getTotalSupply(),
        service.getProductStatus(),
        service.fundType(),
    ]);

    const [
        name,
        symbol,
        description,
        decimals,
        status,
        owner,
        price,
        tokensValue,
        ethBalance,
        accumulatedFee,
    ] = await Promise.all([
        service.getName(),
        service.getSymbol(),
        service.getDescription(),
        service.decimals(),
        service.getStatus(),
        service.getOwner(),
        service.getPrice(),
        service.getTotalWeiAssetsValue(),
        service.getETHBalance(),
        service.getAccumulatedFee(),
    ]);

    return {
        name,
        symbol,
        description,
        decimals,
        status,
        owner,
        price,
        tokensValue,
        ethBalance,
        accumulatedFee,
        version,
    };
}

/**
 * example for how to use factory to get OlympusIndex data
 * @param address address
 */
async function getOlympusIndexData(address: string) {

    const factory = DerivativeFactory.get();
    const service = await factory.getOlympusIndex(address);
    const version = await service.getVersion();

    const [totalSupply, productStatus, fundType] = await Promise.all([
        service.getTotalSupply(),
        service.getProductStatus(),
        service.fundType(),
    ]);

    const [
        name,
        symbol,
        description,
        decimals,
        status,
        owner,
        price,
        tokensValue,
        ethBalance,
        accumulatedFee,
    ] = await Promise.all([
        service.getName(),
        service.getSymbol(),
        service.getDescription(),
        service.decimals(),
        service.getStatus(),
        service.getOwner(),
        service.getPrice(),
        service.getTotalWeiAssetsValue(),
        service.getETHBalance(),
        service.getAccumulatedFee(),
    ]);

    return {
        name,
        symbol,
        description,
        decimals,
        status,
        owner,
        price,
        tokensValue,
        ethBalance,
        accumulatedFee,
        version,
    };
}
