package app.closer.data.repository

import app.closer.data.remote.FirestoreBucketListDataSource
import app.closer.domain.model.BucketListItem
import app.closer.domain.repository.BucketListRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
import javax.inject.Singleton

/**
 * Implementation of [BucketListRepository].
 *
 * Firestore-backed: Shared bucket list items observed in real-time via
 * Firestore snapshot listeners. All items are stored under couples/{coupleId}/bucket_list/.
 */
@Singleton
class BucketListRepositoryImpl @Inject constructor(
    private val dataSource: FirestoreBucketListDataSource
) : BucketListRepository {

    // ─── CRUD methods ────────────────────────────────────────────────────────

    override suspend fun addItem(item: BucketListItem): String {
        return dataSource.addItem(item.coupleId, item)
    }

    override suspend fun updateItem(item: BucketListItem) {
        dataSource.updateItem(item.coupleId, item)
    }

    override suspend fun getItem(coupleId: String, itemId: String): BucketListItem? {
        return dataSource.getItem(coupleId, itemId)
    }

    override suspend fun getItems(coupleId: String): List<BucketListItem> {
        return dataSource.getItems(coupleId)
    }

    override suspend fun deleteItem(coupleId: String, itemId: String) {
        dataSource.deleteItem(coupleId, itemId)
    }

    // ─── Completion methods ──────────────────────────────────────────────────

    override suspend fun completeItem(coupleId: String, itemId: String, completedBy: String) {
        dataSource.completeItem(coupleId, itemId, completedBy)
    }

    // ─── Category methods ────────────────────────────────────────────────────

    override suspend fun getItemsByCategory(coupleId: String, category: String): List<BucketListItem> {
        return dataSource.getItemsByCategory(coupleId, category)
    }

    // ─── Observation methods ─────────────────────────────────────────────────

    override fun observeItems(coupleId: String): Flow<List<BucketListItem>> {
        return dataSource.observeItems(coupleId)
    }

    override fun observeItemsByCategory(coupleId: String, category: String): Flow<List<BucketListItem>> {
        return dataSource.observeItemsByCategory(coupleId, category)
    }
}
