package com.zaojiao.app.data.remote

import com.zaojiao.app.core.common.state.DataState
import com.zaojiao.app.data.model.TokenModel
import com.zaojiao.app.data.remote.api.LoginApi
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class RemoteLoginData @Inject constructor(
    private val loginApi: LoginApi,
) {
    suspend fun loginBySms(phone: String, code: String): DataState<TokenModel?> {
        return try {
            val result = loginApi.loginBySms(phone, code).data
            DataState.Success(result)
        } catch (throwable: Throwable) {
            DataState.Failure(throwable)
        }
    }

    suspend fun loginByWechat(code: String): DataState<TokenModel?> {
        return try {
            val result = loginApi.loginByWechat(code).data
            DataState.Success(result)
        } catch (throwable: Throwable) {
            DataState.Failure(throwable)
        }
    }

    suspend fun loginByOneClick(code: String): DataState<TokenModel?> {
        return try {
            val result = loginApi.loginByOneClick(code).data
            DataState.Success(result)
        } catch (throwable: Throwable) {
            DataState.Failure(throwable)
        }
    }
}