// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

package org.yuzu.yuzu_emu.features.settings.model.view

import androidx.annotation.StringRes
import org.yuzu.yuzu_emu.features.settings.model.AbstractByteSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractFloatSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractShortSetting

class SpinBoxSetting(
    setting: AbstractSetting,
    @StringRes titleId: Int = 0,
    titleString: String = "",
    @StringRes descriptionId: Int = 0,
    descriptionString: String = "",
    val valueHint: Int,
    val min: Int,
    val max: Int
) : SettingsItem(setting, titleId, titleString, descriptionId, descriptionString) {
    override val type = TYPE_SPINBOX

    fun getSelectedValue(needsGlobal: Boolean = false) =
        when (setting) {
            is AbstractByteSetting -> setting.getByte(needsGlobal).toInt()
            is AbstractShortSetting -> setting.getShort(needsGlobal).toInt()
            is AbstractIntSetting -> setting.getInt(needsGlobal)
            is AbstractFloatSetting -> setting.getFloat(needsGlobal).toInt()
            else -> 0
        }

    fun setSelectedValue(value: Int) =
        when (setting) {
            is AbstractByteSetting -> setting.setByte(value.toByte())
            is AbstractShortSetting -> setting.setShort(value.toShort())
            is AbstractFloatSetting -> setting.setFloat(value.toFloat())
            else -> (setting as AbstractIntSetting).setInt(value)
        }
}