package com.zaojiao.app.data.repo.impl

import com.zaojiao.app.core.common.remote.di.ApplicationScope
import com.zaojiao.app.core.common.state.DataState
import com.zaojiao.app.data.model.TokenModel
import com.zaojiao.app.data.remote.RemoteLoginData
import com.zaojiao.app.data.repo.LoginRepository
import com.zaojiao.app.data.repo.LoginState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class LoginRepositoryImpl @Inject constructor(
    private val remoteLoginData: RemoteLoginData,
    @ApplicationScope private val coroutineScope: CoroutineScope,
) : LoginRepository {

    override val state: Flow<LoginState> = flow {
        emit(LoginState.IN)
    }

    override fun loginBySms(phone: String, code: String) {
        coroutineScope.launch {
            processTokenData(remoteLoginData.loginBySms(phone, code))
        }
    }

    override fun loginByWechat(code: String) {
        coroutineScope.launch {
            processTokenData(remoteLoginData.loginByWechat(code))
        }
    }

    override fun loginByOneClick(code: String) {
        coroutineScope.launch {
            processTokenData(remoteLoginData.loginByOneClick(code))
        }
    }

    private suspend fun processTokenData(state: DataState<TokenModel?>) {

    }

    override fun logout() {
        coroutineScope.launch {

        }
    }
}