package com.gestoreasy.repository

import com.gestoreasy.database.dao.ProductDao
import com.gestoreasy.database.entities.Product
import kotlinx.coroutines.flow.Flow

class ProductRepository(private val productDao: ProductDao) {
    suspend fun insert(product: Product): Long {
        return productDao.insert(product)
    }
    
    suspend fun update(product: Product) {
        productDao.update(product)
    }
    
    suspend fun insertOrUpdate(product: Product) {
        productDao.insertOrUpdate(product)
    }
    
    suspend fun getById(id: Long): Product? {
        return productDao.getById(id)
    }
    
    suspend fun getAll(): List<Product> {
        return productDao.getAll()
    }
    
    suspend fun getActive(): List<Product> {
        return productDao.getActive()
    }
    
    suspend fun search(query: String): List<Product> {
        return productDao.search("%$query%")
    }
    
    suspend fun getLastSyncTime(): Long {
        return productDao.getLastSyncTime() ?: 0
    }
    
    suspend fun updateLastSyncTime(timestamp: Long) {
        productDao.updateLastSyncTime(timestamp)
    }
    
    fun getAllFlow(): Flow<List<Product>> {
        return productDao.getAllFlow()
    }
}

