// Copyright (C) 2020-2022 Notus Network
//
// Notus Network is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
// project or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

import {
  NetworkLayer,
  NetworkType,
  CurrencyList,
  WalletBalanceStruct,
  CryptoTransactionResult,
  BlockStatusCode,
} from '../types';
import {FindAvailableNode} from '../core';

export async function GetCurrencyList(currentNetwork: NetworkType) {
  let res: CurrencyList = JSON.parse(
    await FindAvailableNode(
      'currency/list/',
      currentNetwork,
      NetworkLayer.Layer1,
    ),
  );
  return res;
}

export async function GetBalance(
  walletKey: string,
  currentNetwork: NetworkType,
) {
  let res: WalletBalanceStruct = JSON.parse(
    await FindAvailableNode(
      'balance/' + walletKey + '/',
      currentNetwork,
      NetworkLayer.Layer1,
    ),
  );
  return res.Balance;
}

export async function Airdrop(walletKey: string, currentNetwork: NetworkType) {
  let res: CryptoTransactionResult = JSON.parse(
    await FindAvailableNode(
      'airdrop/' + walletKey + '/',
      currentNetwork,
      NetworkLayer.Layer1,
    ),
  );
  return res;
}

export async function GetStatus(
  BlockUid: string,
  currentNetwork: NetworkType,
  currentLayer: NetworkLayer,
) {
  let res: BlockStatusCode = JSON.parse(
    await FindAvailableNode(
      'status/' + BlockUid + '/',
      currentNetwork,
      currentLayer,
    ),
  );
  return res;
}
