package com.narutohuo.xindazhou.common.version.datasource.remote

import com.narutohuo.xindazhou.common.network.ApiBaseRemoteDataSource
import com.narutohuo.xindazhou.common.version.model.VersionResponse

/**
 * 版本远程数据源接口
 */
interface VersionRemoteDataSource {
    /**
     * 获取最新版本
     */
    suspend fun getLatestVersion(
        platform: Int,
        currentVersionCode: Int?
    ): Result<VersionResponse>
}

/**
 * 版本远程数据源实现
 * 
 * 继承 ApiBaseRemoteDataSource，自动获得：
 * - 统一的错误处理
 * - 自动日志记录
 * - 网络异常友好提示
 * - 线程自动切换
 */
class VersionRemoteDataSourceImpl : ApiBaseRemoteDataSource(), VersionRemoteDataSource {
    
    private val versionApi: VersionApi by lazy {
        com.narutohuo.xindazhou.common.network.ApiManager.create<VersionApi>()
    }
    
    override suspend fun getLatestVersion(
        platform: Int,
        currentVersionCode: Int?
    ): Result<VersionResponse> {
        return executeRequest(
            request = { versionApi.getLatestVersion(platform, currentVersionCode) },
            errorMessage = "版本检查失败"
        )
    }
}

