@file:Suppress("UNCHECKED_CAST", "USELESS_CAST", "INAPPLICABLE_JVM_NAME")
package uts.sdk.modules.wuwxStepCounter;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import io.dcloud.uniapp.*;
import io.dcloud.uniapp.extapi.*;
import io.dcloud.uts.*;
import io.dcloud.uts.Map;
import io.dcloud.uts.Set;
import io.dcloud.uts.UTSAndroid;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.Deferred;
import kotlinx.coroutines.Dispatchers;
import kotlinx.coroutines.async;
open class StartStepCountingUpdatesOptions (
    open var stepCounts: Int? = null,
    open var handler: (numberOfSteps: Float, timestamp: Date, error: Any) -> Unit,
) : UTSObject()
open class QueryStepCountStartingOptions (
    open var start: Date? = null,
    open var end: Date? = null,
    open var handler: (numberOfSteps: Int, error: Any) -> Unit,
) : UTSObject()
var successHandler = fun(numberOfSteps: Float, timestamp: Date, error: Any){};
open class StepCounterSensorEventListener : SensorEventListener {
    override fun onSensorChanged(event: SensorEvent): Unit {
        successHandler(event.values[0], Date(), "");
    }
    override fun onAccuracyChanged(sensor: Sensor, param1: Int): Unit {}
}
fun startStepCountingUpdates(options: StartStepCountingUpdatesOptions) {
    var stepCounterSensorEventListener = StepCounterSensorEventListener();
    successHandler = options.handler;
    val context = UTSAndroid.getAppContext();
    if (context != null) {
        val sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager;
        sensorManager.unregisterListener(stepCounterSensorEventListener, sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER));
        sensorManager.registerListener(stepCounterSensorEventListener, sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER), SensorManager.SENSOR_DELAY_NORMAL);
    }
}
fun stopStepCountingUpdates() {}
fun queryStepCountStarting(options: QueryStepCountStartingOptions) {}
fun isStepCountingAvailable() {}
open class StartStepCountingUpdatesOptionsJSONObject : UTSJSONObject() {
    open var stepCounts: Int? = null;
    open lateinit var handler: UTSCallback;
}
open class QueryStepCountStartingOptionsJSONObject : UTSJSONObject() {
    open var start: Date? = null;
    open var end: Date? = null;
    open lateinit var handler: UTSCallback;
}
fun startStepCountingUpdatesByJs(options: StartStepCountingUpdatesOptionsJSONObject) {
    return startStepCountingUpdates(StartStepCountingUpdatesOptions(stepCounts = options.stepCounts, handler = fun(numberOfSteps: Float, timestamp: Date, error: Any): Unit {
        options.handler(numberOfSteps, timestamp, error);
    }
    ));
}
fun stopStepCountingUpdatesByJs() {
    return stopStepCountingUpdates();
}
fun queryStepCountStartingByJs(options: QueryStepCountStartingOptionsJSONObject) {
    return queryStepCountStarting(QueryStepCountStartingOptions(start = options.start, end = options.end, handler = fun(numberOfSteps: Int, error: Any): Unit {
        options.handler(numberOfSteps, error);
    }
    ));
}
fun isStepCountingAvailableByJs() {
    return isStepCountingAvailable();
}
