package com.example.cmake_project_test

/**
 * 滤波器设置类
 * 管理各种信号处理的参数配置
 */
data class FilterSettings(
    // 采样率设置
    val sampleRate: Double = 1000.0,
    
    // EEG滤波器参数
    val eegLowPass: Double = 40.0,
    val eegHighPass: Double = 1.0,
    
    // ECG滤波器参数
    val ecgHighPass: Double = 0.5,      // 高通滤波，去除基线漂移
    val ecgLowPass: Double = 40.0,      // 低通滤波，去除高频噪声
    val ecgNotchFreq: Double = 50.0,    // 陷波频率，去除工频干扰
    val ecgNotchQ: Double = 30.0,       // 陷波品质因数
    
    // PPG滤波器参数
    val ppgLowPass: Double = 8.0,       // 低通滤波，PPG主要频率范围
    
    // 通用滤波器参数
    val generalLowPass: Double = 100.0,
    val generalHighPass: Double = 0.1,
    val generalNotchFreq: Double = 50.0,
    val generalNotchQ: Double = 30.0
) {
    companion object {
        // 预设配置
        val EEG_DEFAULT = FilterSettings(
            sampleRate = 1000.0,
            eegLowPass = 40.0,
            eegHighPass = 1.0
        )
        
        val ECG_DEFAULT = FilterSettings(
            sampleRate = 1000.0,
            ecgHighPass = 0.5,
            ecgLowPass = 40.0,
            ecgNotchFreq = 50.0,
            ecgNotchQ = 30.0
        )
        
        val PPG_DEFAULT = FilterSettings(
            sampleRate = 1000.0,
            ppgLowPass = 8.0
        )
        
        val HIGH_QUALITY = FilterSettings(
            sampleRate = 1000.0,
            eegLowPass = 50.0,
            eegHighPass = 0.5,
            ecgHighPass = 0.3,
            ecgLowPass = 50.0,
            ecgNotchFreq = 50.0,
            ecgNotchQ = 50.0,
            ppgLowPass = 10.0
        )
        
        val REAL_TIME = FilterSettings(
            sampleRate = 1000.0,
            eegLowPass = 30.0,
            eegHighPass = 2.0,
            ecgHighPass = 1.0,
            ecgLowPass = 30.0,
            ecgNotchFreq = 50.0,
            ecgNotchQ = 20.0,
            ppgLowPass = 6.0
        )
    }
    
    /**
     * 根据数据类型获取相应的滤波器设置
     */
    fun getSettingsForDataType(dataType: type.SensorData.DataType): FilterSettings {
        return when (dataType) {
            type.SensorData.DataType.EEG -> EEG_DEFAULT
            type.SensorData.DataType.ECG_2LEAD, type.SensorData.DataType.ECG_12LEAD -> ECG_DEFAULT
            type.SensorData.DataType.PPG -> PPG_DEFAULT
            else -> this
        }
    }
    
    /**
     * 更新采样率
     */
    fun updateSampleRate(newSampleRate: Double): FilterSettings {
        return copy(sampleRate = newSampleRate)
    }
    
    /**
     * 更新EEG滤波器参数
     */
    fun updateEEGSettings(
        lowPass: Double? = null,
        highPass: Double? = null
    ): FilterSettings {
        return copy(
            eegLowPass = lowPass ?: eegLowPass,
            eegHighPass = highPass ?: eegHighPass
        )
    }
    
    /**
     * 更新ECG滤波器参数
     */
    fun updateECGSettings(
        highPass: Double? = null,
        lowPass: Double? = null,
        notchFreq: Double? = null,
        notchQ: Double? = null
    ): FilterSettings {
        return copy(
            ecgHighPass = highPass ?: ecgHighPass,
            ecgLowPass = lowPass ?: ecgLowPass,
            ecgNotchFreq = notchFreq ?: ecgNotchFreq,
            ecgNotchQ = notchQ ?: ecgNotchQ
        )
    }
    
    /**
     * 更新PPG滤波器参数
     */
    fun updatePPGSettings(lowPass: Double? = null): FilterSettings {
        return copy(ppgLowPass = lowPass ?: ppgLowPass)
    }
}
