package com.example.wabi.domain.supabase

import android.util.Log
import com.example.wabi.models.responses.Response
import io.github.jan.supabase.SupabaseClient
import io.github.jan.supabase.auth.auth
import io.github.jan.supabase.auth.providers.builtin.Email
import javax.inject.Inject


class SupabaseServiceImpl @Inject constructor(private val supabase: SupabaseClient) :
    SupabaseService {
    override suspend fun signIn(userEmail: String, userPasword: String): Response {
        return try {
            var user = supabase.auth.signInWith(Email) {
                email = userEmail
                password = userPasword
            }
            Log.d("signIn", "The user is logged in")
            Response(user.toString())
        } catch (ex: Exception) {
            Log.e("signIn", ex.message.toString())
            Response("", ex.message.toString())
        }
    }

    override suspend fun signOut(): Response {
        return try {
            val response = supabase.auth.signOut()
            Log.d("signOut", "The user logged out")
            Response(response.toString())
        } catch (e: Exception) {
            Log.d("signOut", e.message.toString())
            Response("", e.message.toString())
        }
    }

    override suspend fun signUp(): Response {
        TODO("Not yet implemented")
    }

    override suspend fun addUser(): Response {
        TODO("Not yet implemented")
    }
}