package cy.hexor.furumi.domain.model

data class AuthTokens(
    val accessToken: String,
    val refreshToken: String,
    val tokenType: String = DEFAULT_TOKEN_TYPE,
    val expiresInSeconds: Int,
    val expiresAtEpochSeconds: Long = 0L
) {
    val authorizationHeader: String
        get() = "${tokenType.ifBlank { DEFAULT_TOKEN_TYPE }} $accessToken"

    fun isExpired(nowEpochSeconds: Long, skewSeconds: Long = DEFAULT_EXPIRY_SKEW_SECONDS): Boolean {
        return expiresAtEpochSeconds > 0 && nowEpochSeconds >= expiresAtEpochSeconds - skewSeconds
    }

    companion object {
        const val DEFAULT_TOKEN_TYPE = "Bearer"
        private const val DEFAULT_EXPIRY_SKEW_SECONDS = 60L
    }
}
