package dev.inmo.postssystem.features.auth.server.tokens

import com.soywiz.klock.DateTime
import dev.inmo.postssystem.features.auth.common.AuthToken
import dev.inmo.postssystem.features.auth.common.RefreshToken
import dev.inmo.postssystem.features.users.common.UserId
import dev.inmo.micro_utils.repos.CRUDRepo

data class AuthTokenModel(
    val token: AuthToken,
    val refreshToken: RefreshToken,
    val userId: UserId,
    val expiring: DateTime,
    val die: DateTime
)

interface AuthTokensRepo : CRUDRepo<AuthTokenModel, AuthToken, AuthTokenModel> {
    suspend fun getByRefreshToken(refreshToken: RefreshToken): AuthTokenModel?
    suspend fun replaceToken(toRemove: AuthToken, toInsert: AuthTokenModel): Boolean
    suspend fun deleteDied(now: DateTime = DateTime.now())
}

