package com.example.what_the_fantasy.ui.viewModels

import android.util.Log
import androidx.lifecycle.ViewModel
import com.example.what_the_fantasy.data.services.ServicesStub
import com.example.what_the_fantasy.ui.states.AuthUserState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update

class AuthUserViewModel : ViewModel(){
    private val services = ServicesStub() // faire repository qui gère les services Stub et API
    private val _userState = MutableStateFlow(AuthUserState())
    val userState : StateFlow<AuthUserState> = _userState.asStateFlow()



    fun setUsername(username : String){
        _userState.update { it.copy(username=username) }
    }

    fun setPassword(password : String){
        _userState.update { it.copy(password=password) }
    }

    fun validLogin(username : String, passwd : String, navController: (Int) -> Unit, initialierCurrentUser : (Int) -> Unit) : Boolean{
        return services.validLogin(username,passwd, navController, initialierCurrentUser)
    }
}