package com.unitech.utility.btscanner;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import static android.content.Intent.FLAG_RECEIVER_FOREGROUND;

public class util_usu_api {
    //==============================================================================================
    //----------------------------------------------------------------------------------------------
    private final Context context;
    private final String packageName;

    //==============================================================================================
    public util_usu_api(Context context) {
        this.context = context;
        this.packageName = null;
    }

    public util_usu_api(Context context, String packageName) {
        this.context = context;
        this.packageName = packageName;
    }

    //==============================================================================================
    public void SetScanToKey(boolean isEnable) {
        context.sendBroadcast(new Intent().setAction(AllUsageAction.systemScan2key).putExtra("scan2key", isEnable).putExtra("packageName", packageName));
    }

    //==============================================================================================
    public void GetPairingBarcode() {//2.1
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetPairingBarcode).putExtra("packageName", packageName));
    }

    public void GetTargetScannerStatus() {//2.2
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetTargetScannerStatus).putExtra("packageName", packageName));
    }

    public void SetDisconnect() {//2.4
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiUnpaired).putExtra("packageName", packageName));
    }

    public void GetSerialNumber() {//2.5
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetSN).setFlags(FLAG_RECEIVER_FOREGROUND).putExtra("packageName", packageName));
    }

    public void GetRemoteBTName() {//2.6
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetName).putExtra("packageName", packageName));
    }

    public void GetRemoteBTAddress() {//2.7
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetAddress).putExtra("packageName", packageName));
    }

    public void GetFirmwareVersion() {//2.8
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetFW).putExtra("packageName", packageName));
    }

    public void GetBattery() {//2.9
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetBattery).putExtra("packageName", packageName));
    }

    //==============================================================================================
    public void GetTrigger() {//3.1
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetTrigger).putExtra("packageName", packageName));
    }

    public void SetTrigger(boolean status) {//3.1
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetTrigger).putExtra("trig", status).putExtra("packageName", packageName));
    }

    public void StartDecode() {//3.2
        context.sendBroadcast(new Intent().setAction(AllUsageAction.aipStartDecode).putExtra("packageName", packageName));
    }

    public void StopDecode() {//3.3
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiStopDecode).putExtra("packageName", packageName));
    }

    public void GetACK() {//3.4
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetAck).putExtra("packageName", packageName));
    }

    public void SetACK(boolean ack) {//3.4
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetAck).putExtra("ack", ack).putExtra("packageName", packageName));
    }

    public void GetAutoConnect() {//3.5
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetAutoConnection).putExtra("packageName", packageName));
    }

    public void SetAutoConnect(boolean autoConn) {//3.5
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetAutoConnection).putExtra("autoConn", autoConn).putExtra("packageName", packageName));
    }

    public void GetConfiguration() {//3.6
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetConfig).putExtra("packageName", packageName));
    }

    public void SetConfiguration(String appendix, int value) {//3.6
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetConfig).putExtra(appendix, value).putExtra("packageName", packageName));
    }

    public void SetConfiguration(Bundle bundle) {//3.6
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetConfig).putExtras(bundle).putExtra("packageName", packageName));
    }

    public void GetBTSignalCheckingLevel() {//3.7
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetBtSignalCheckingLevel).putExtra("packageName", packageName));
    }

    public void SetBTSignalCheckingLevel(int level) {//3.7
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetBtSignalCheckingLevel).putExtra("btSignalCheckingLevel", level).putExtra("packageName", packageName));
    }

    public void GetDataTerminator() {//3.8
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetDataTerminator).putExtra("packageName", packageName));
    }

    public void SetDataTerminator(int parseInt) {//3.8
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetDataTerminator).putExtra("DataTerminator", parseInt).putExtra("packageName", packageName));
    }

    //==============================================================================================
    public void GetFormat() {//4.1
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetFormat).putExtra("packageName", packageName));
    }

    public void SetSSIMode() {//4.1
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiChangeToFormatSsi).putExtra("packageName", packageName));
    }

    public void SetRAWMode() {//4.1
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiChangeToFormatRaw).putExtra("packageName", packageName));
    }

    public void getIntentAction() {//4.1
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetIntentAction).putExtra("packageName", packageName));
    }

    public void setIntentAction(String actionName, String dataKey, String dataTypeKey, String dataLengthKey, String dataByteKey, boolean enableType, boolean enableLength, boolean enableByte) {//4.1
        Bundle mBundle = new Bundle();
        mBundle.putString("actionName", actionName);
        mBundle.putString("dataKey", dataKey);
        mBundle.putString("dataTypeKey", dataTypeKey);
        mBundle.putString("dataLengthKey", dataLengthKey);
        mBundle.putString("dataByteKey", dataByteKey);
        mBundle.putBoolean("enableByte", enableByte);
        mBundle.putBoolean("enableType", enableType);
        mBundle.putBoolean("enableLength", enableLength);
        context.sendBroadcast(new Intent(AllUsageAction.apiSetIntentAction)
                .putExtras(mBundle)
                .putExtra("packageName", packageName));
    }

    public void SetIndicator(Bundle bundle) {//4.2
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetIndicator).putExtras(bundle).putExtra("packageName", packageName));
    }

    //==============================================================================================
    public void ExportSettings(String filepath) {//5.1
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiExportSettings).putExtra("filepath", filepath).putExtra("packageName", packageName));
    }

    public void ImportSettings(String filepath, String password) {//5.2
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiImportSettings).putExtra("filepath", filepath).putExtra("passcode", password).putExtra("packageName", packageName));
    }

    public void UploadAllSettings() {//5.3
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiUploadSettings).putExtra("packageName", packageName));
    }

    public void resetAllSettings() {//5.4
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiResetSettings).putExtra("packageName", packageName));
    }

    public void getScanToKey() {//5.5
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetScan2key).putExtra("packageName", packageName));
    }

    public void setScanToKey(boolean enable) {//5.5
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetScan2key).putExtra("scan2key", enable).putExtra("packageName", packageName));
    }

    public void apiGetOutput() {//5.6
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetOutput).putExtra("packageName", packageName));
    }

    public void apiSetOutput(Bundle bundle) {//5.6
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetOutput).putExtras(bundle).putExtra("packageName", packageName));
    }

    public void apiGetEncoding() {//5.7
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetEncoding).putExtra("packageName", packageName));
    }

    public void apiSetEncoding(int encoding) {//5.7
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetEncoding).putExtra("encoding", encoding).putExtra("packageName", packageName));
    }

    public void apiGetFormattingStatus() {//5.8
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetFormattingStatus).putExtra("packageName", packageName));
    }

    public void apiSetFormattingStatus(boolean enable) {//5.8
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetFormattingStatus).putExtra("enable", enable).putExtra("packageName", packageName));
    }

    public void apiGetAppend() {//5.9
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetAppend).putExtra("packageName", packageName));
    }

    public void apiSetAppend(Bundle bundle) {//5.9
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetAppend).putExtras(bundle).putExtra("packageName", packageName));
    }

    public void apiGetReplace() {//5.10
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetReplace).putExtra("packageName", packageName));
    }

    public void apiSetReplace(Bundle bundle) {//5.10
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetReplace).putExtras(bundle).putExtra("packageName", packageName));
    }

    public void apiGetRemoveNonPrintableChar() {//5.11
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetRemoveNonPrintableChar).putExtra("packageName", packageName));
    }

    public void apiSetRemoveNonPrintableChar(boolean enable) {//5.11
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetRemoveNonPrintableChar).putExtra("enable", enable).putExtra("packageName", packageName));
    }

    public void apiGetFormatting() {//5.12
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetFormatting).putExtra("packageName", packageName));
    }

    public void apiSetFormatting(String formatting) {//5.12
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetFormatting).putExtra("formatting", formatting).putExtra("packageName", packageName));
    }

    public void apiDeleteFormatting(int type) {//5.12
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiDeleteFormatting).putExtra("type", type).putExtra("packageName", packageName));
    }

    public void apiGetFloatingButton() {//5.13
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetFloatingButton).putExtra("packageName", packageName));
    }

    public void apiSetFloatingButton(boolean enable) {//5.13
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetFloatingButton).putExtra("enable", enable).putExtra("packageName", packageName));
    }

    public void apiGetSound() {//5.14
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetSound).putExtra("packageName", packageName));
    }

    public void apiSetSound(Bundle bundle) {//5.14
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetSound).putExtras(bundle).putExtra("packageName", packageName));
    }

    public void apiGetVibration() {//5.15
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetVibration).putExtra("packageName", packageName));
    }

    public void apiSetVibration(boolean enable) {//5.15
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetVibration).putExtra("enable", enable).putExtra("packageName", packageName));
    }

    public void apiGetStartup() {//5.16
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetStartup).putExtra("packageName", packageName));
    }

    public void apiSetStartup(boolean enable) {//5.16
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetStartup).putExtra("enable", enable).putExtra("packageName", packageName));
    }

    public void apiGetAutoEnforceSettings() {//5.17
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiGetAutoEnforceSettings).putExtra("packageName", packageName));
    }

    public void apiSetAutoEnforceSettings(boolean enable) {//5.17
        context.sendBroadcast(new Intent().setAction(AllUsageAction.apiSetAutoEnforceSettings).putExtra("enable", enable).putExtra("packageName", packageName));
    }
    //==============================================================================================
}
