package com.narutohuo.xindazhou.user.datasource.local

import com.narutohuo.xindazhou.user.model.LoginResponse

/**
 * 认证本地数据源接口
 */
interface AuthLocalDataSource {
    /**
     * 保存Token
     */
    suspend fun saveToken(loginResponse: LoginResponse)
    
    /**
     * 获取Access Token
     */
    suspend fun getToken(): String?
    
    /**
     * 清除Token
     */
    suspend fun clearToken()
}

/**
 * 认证本地数据源实现
 */
class AuthLocalDataSourceImpl : AuthLocalDataSource {
    
    override suspend fun saveToken(loginResponse: LoginResponse) {
        TokenManager.saveToken(
            loginResponse.accessToken,
            loginResponse.refreshToken,
            loginResponse.userId
        )
    }
    
    override suspend fun getToken(): String? {
        return TokenManager.getAccessToken()
    }
    
    override suspend fun clearToken() {
        TokenManager.clearToken()
    }
}

