package kr.lunaticbum.back.lun.model

import lombok.AllArgsConstructor
import lombok.Data
import lombok.NoArgsConstructor
import org.springframework.data.annotation.Id
import org.springframework.data.mongodb.core.index.Indexed
import org.springframework.data.mongodb.core.mapping.Document
import org.springframework.data.mongodb.repository.ReactiveMongoRepository
import org.springframework.stereotype.Repository
import reactor.core.publisher.Mono
import java.time.LocalDateTime
import java.util.*


@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "TokenData")
class TokenData {
    @Indexed(name = "ttl",expireAfterSeconds = 0)
    var expireAt: LocalDateTime? = null

    @Id
    var tokenKey : String? = null

    var refreshToken : String? = null

    constructor(tokenKey: String?, refreshToken: String?) {
        this.expireAt = LocalDateTime.now().plusSeconds(500)
        this.tokenKey = tokenKey
        this.refreshToken = refreshToken
    }
}


@Repository
interface TokenDataRepository : ReactiveMongoRepository<TokenData, String> {
    fun findBytokenKey(tokenKey: String): Mono<TokenData>
    fun deleteBytokenKey(tokenKey: String)
}