package com.example.what_the_fantasy.ui.viewModels

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

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

    fun createUser(username: String, email: String, passwd: String) : Boolean{
        return services.CreateUser(username, email, passwd)
    }

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

    fun setEmail(email : String){
        _userState.update { it.copy(email=email) }
    }

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

}