package com.diegocayo.organizame.data.repository

import com.diegocayo.organizame.data.local.datasource.PreferencesDataSource
import com.diegocayo.organizame.data.mapper.toDomain
import com.diegocayo.organizame.data.mapper.toDto
import com.diegocayo.organizame.domain.model.User
import com.diegocayo.organizame.domain.repository.UserRepository
import javax.inject.Inject

class UserRepositoryImpl @Inject constructor(
    private val preferencesDataSource: PreferencesDataSource
) : UserRepository {

    override suspend fun saveUser(user: User) {
        preferencesDataSource.saveUser(user.toDto())
    }

    override suspend fun getUser(): User? {
        return preferencesDataSource.getUser()?.toDomain()
    }

    override suspend fun updateLoginStatus(isLoggedIn: Boolean) {
        preferencesDataSource.setLoginStatus(isLoggedIn)
    }

    override suspend fun clearUser() {
        preferencesDataSource.clearUser()
    }
}