package llc.arma.ble.domain.repository

import kotlinx.coroutines.flow.Flow
import llc.arma.ble.domain.Result
import llc.arma.ble.domain.common.BleException
import llc.arma.ble.domain.common.ProgressState
import llc.arma.ble.domain.model.Ble
import llc.arma.ble.domain.model.BleInfo
import llc.arma.ble.domain.usecase.AccelScale
import llc.arma.ble.domain.usecase.AccelViewMode
import llc.arma.ble.domain.usecase.FftAxis
import llc.arma.ble.domain.usecase.FftFrequency
import llc.arma.ble.domain.usecase.FftViewMode

interface BleRepository {

    fun getFoundBle(): List<BleInfo>

    fun getBleAroundFlow(): Result<Flow<List<BleInfo>>, BleException>

    suspend fun getBleBySerial(serial: String) : Result<Flow<Ble>, BleException>

    suspend fun getTemperatureHistoryBySerial(
        serial: String
    ): Flow<Result<ProgressState<List<Ble.Thermometer.HistoryPoint>>, BleException>>

    suspend fun writeBle(
        serial: String,
        request: Ble.Thermometer.WriteRequest
    ): Result<Unit, BleException>

    suspend fun writeBle(
        serial: String,
        request: Ble.Beacon.WriteRequest
    ): Result<Unit, BleException>

    suspend fun writeBle(
        serial: String,
        request: Ble.Host.WriteRequest
    ): Result<Unit, BleException>

    suspend fun writeBle(
        serial: String,
        request: Ble.Accelerometer.WriteRequest
    ): Result<Unit, BleException>

    suspend fun changeBlePassword(
        password: String,
        serial: String
    ): Result<Unit, BleException>

    fun getAccelerometerMeasureBySerialFlow(
        serial: String,
        accelScale: AccelScale,
        accelMode: AccelViewMode,
        fftAxis: FftAxis,
        fftMode: FftViewMode,
        frequency: FftFrequency
    ): Flow<Result<Ble.Accelerometer.RealtimePoint, BleException>>

    suspend fun getAccelerometerSpectreBySerial(
        serial: String,
        accelScale: AccelScale,
        accelMode: AccelViewMode,
        fftAxis: FftAxis,
        fftMode: FftViewMode,
        frequency: FftFrequency
    ): Flow<Result<ProgressState<List<Ble.Accelerometer.SpectrePoint>>, BleException>>

    suspend fun getAccelerometerHistoryBySerial(
        serial: String
    ): Flow<Result<ProgressState<List<Ble.Accelerometer.HistoryPoint>>, BleException>>

    suspend fun getHostHistoryBySerial(
        serial: String
    ): Flow<Result<ProgressState<List<Ble.Host.HistoryPoint>>, BleException>>

    suspend fun getHostBleTableBySerial(
        serial: String
    ): Result<List<String>, BleException>

    suspend fun addBleToHostTableBySerial(
        serial: String,
        ble: List<String>
    ): Result<Int, BleException>

}