/*
 * Copyright (c) 2019 - 2026 AB Circle Limited. All rights reserved
 */

package com.abc.bluetoothdemo;

import com.abc.bluetoothTerminalfactory.AbCircleCardTerminalBluetooth;

import javax.smartcardio.CardTerminal;

public class BluetoothTerminalHelper {

    static int getBatteryLevel(CardTerminal terminal) {
        if (terminal == null) {
            throw new IllegalArgumentException("Terminal not found");
        }

        if (!(terminal instanceof AbCircleCardTerminalBluetooth)) {
            throw new IllegalArgumentException("Is not AbCircleCardTerminalBluetooth");
        } else {
            return ((AbCircleCardTerminalBluetooth) terminal).getBatteryLevel();
        }
    }

    static int getBatteryMillivolts(CardTerminal terminal) {
        if (terminal == null) {
            throw new IllegalArgumentException("Terminal not found");
        }

        if (!(terminal instanceof AbCircleCardTerminalBluetooth)) {
            throw new IllegalArgumentException("Is not AbCircleCardTerminalBluetooth");
        } else {
            return ((AbCircleCardTerminalBluetooth) terminal).getBatteryLevel(2);
        }
    }

    static String getFirmwareVersion(CardTerminal terminal) {
        if (terminal == null) {
            throw new IllegalArgumentException("Terminal not found");
        }

        if (!(terminal instanceof AbCircleCardTerminalBluetooth)) {
            throw new IllegalArgumentException("Is not AbCircleCardTerminalBluetooth");
        } else {
            return ((AbCircleCardTerminalBluetooth) terminal).getFirmwareVersion();
        }
    }

    static String getSerialNumber(CardTerminal terminal) {
        if (terminal == null) {
            throw new IllegalArgumentException("Terminal not found");
        }

        if (!(terminal instanceof AbCircleCardTerminalBluetooth)) {
            throw new IllegalArgumentException("Is not AbCircleCardTerminalBluetooth");
        } else {
            return ((AbCircleCardTerminalBluetooth) terminal).getSerialNumber();
        }
    }

    static boolean isACKProtocolEnabled(CardTerminal terminal) {
        if (terminal == null) {
            throw new IllegalArgumentException("Terminal not found");
        }

        if (!(terminal instanceof AbCircleCardTerminalBluetooth)) {
            throw new IllegalArgumentException("Is not AbCircleCardTerminalBluetooth");
        } else {
            return ((AbCircleCardTerminalBluetooth) terminal).isACKProtocolEnabled();
        }
    }
    static void disconnectTerminal(CardTerminal terminal) {
        if (terminal == null) {
            throw new IllegalArgumentException("Terminal not found");
        }

        if (!(terminal instanceof AbCircleCardTerminalBluetooth)) {
            throw new IllegalArgumentException("Is not AbCircleCardTerminalBluetooth");
        } else {
            ((AbCircleCardTerminalBluetooth) terminal).disconnect();
        }
    }
}
