package com.diegocayo.organizame.data.repository

import com.diegocayo.organizame.data.local.dao.SubjectDao
import com.diegocayo.organizame.data.mapper.toEntity
import com.diegocayo.organizame.data.mapper.toModel
import com.diegocayo.organizame.domain.model.Subject
import com.diegocayo.organizame.domain.repository.SubjectRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class SubjectRepositoryImpl @Inject constructor(
    private val subjectDao: SubjectDao
) : SubjectRepository {

    override fun getAllSubjects(): Flow<List<Subject>> =
        subjectDao.getAllSubjects().map { entities ->
            entities.map { it.toModel() }
        }

    override suspend fun getSubjectById(id: Long): Subject? =
        subjectDao.getSubjectById(id)?.toModel()

    override suspend fun insertSubject(subject: Subject): Long =
        subjectDao.insertSubject(subject.toEntity())

    override suspend fun updateSubject(subject: Subject) {
        subjectDao.updateSubject(subject.toEntity())
    }

    override suspend fun deleteSubject(subject: Subject) {
        subjectDao.deleteSubject(subject.toEntity())
    }

    override suspend fun deleteAllSubjects() {
        subjectDao.deleteAllSubjects()
    }
} 