package top.r3944realms.ltdmanager.whitelist.request

import io.ktor.http.HeadersBuilder
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import top.r3944realms.ltdmanager.core.client.request.IRequest
import top.r3944realms.ltdmanager.core.config.YamlConfigLoader
import top.r3944realms.ltdmanager.whitelist.response.FailedWhitelistSystemResponse
import top.r3944realms.ltdmanager.whitelist.response.WhitelistSystemResponse

@Serializable
abstract class WhitelistSystemRequest(
    @Transient
    override val createTime: Long = System.currentTimeMillis()
) : IRequest<WhitelistSystemResponse, FailedWhitelistSystemResponse> {

    /** 自动注入 X-API-TOKEN 鉴权头 */
    override fun headers(): HeadersBuilder.() -> Unit = {
        super.headers().invoke(this)
        val token = YamlConfigLoader.loadWhitelistSystemConfig().decryptedToken
        if (!token.isNullOrEmpty()) {
            append("X-API-TOKEN", token)
        }
    }
}
