package llc.arma.ble.domain.usecase

import kotlinx.coroutines.flow.Flow
import llc.arma.ble.domain.Result
import llc.arma.ble.domain.common.BleException
import llc.arma.ble.domain.repository.BleRepository
import javax.inject.Inject

class GetAccelerometerMeasureBySerialFlow @Inject constructor(
    private val bleRepository: BleRepository
) {

    operator fun invoke(
        serial: String,
        accelScale: AccelScale,
        accelMode: AccelViewMode,
        fftAxis: FftAxis,
        fftMode: FftViewMode,
        frequency: FftFrequency
    ): Flow<Result<MeasureData, BleException>> {

        return bleRepository.getAccelerometerMeasureBySerialFlow(serial, accelScale, accelMode, fftAxis, fftMode, frequency)

    }

}

enum class AccelViewMode {
    ACCELERATION, PEAK_ACCELERATION, RMS, VIBRATION, ANGLE
}

enum class AccelScale(val k: Int) {
    S_2(2_000), S_4(4_000), S_8(8_000), S_16(16_000)
}

sealed class MeasureData {

    data class Angle(
        val xAngle: Float,
        val yAngle: Float,
        val zAngle: Float,
        val xAccelerate: Float,
        val yAccelerate: Float,
        val zAccelerate: Float,
    ) : MeasureData()

    data class Accelerate(
        val x: Float,
        val y: Float,
        val z: Float,
    ) : MeasureData()

    data class Vibration(
        val value: Float
    ) : MeasureData()

}

data class Accelerate(
    val x: Float,
    val y: Float,
    val z: Float,
)