package com.rosetta.messenger.database

import androidx.room.ColumnInfo
import androidx.room.Dao
import androidx.room.Entity
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.PrimaryKey
import androidx.room.Query

@Entity(tableName = "accounts_sync_times")
data class AccountSyncTimeEntity(
    @PrimaryKey @ColumnInfo(name = "account") val account: String,
    @ColumnInfo(name = "last_sync") val lastSync: Long
)

@Dao
interface SyncTimeDao {
    @Query("SELECT last_sync FROM accounts_sync_times WHERE account = :account LIMIT 1")
    suspend fun getLastSync(account: String): Long?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun upsert(entity: AccountSyncTimeEntity)
}
