unit_ca5/src/main/scala/db/schema/ScopesVersion.scala
2024-06-19 20:55:25 -05:00

48 lines
No EOL
1,002 B
Scala

package unit_ca5.db.schema
import unit_ca5.twitch.TokenScope
trait ScopesVersion:
val scopes: List[TokenScope]
val version: Int
def toScopes(): List[TokenScope] = scopes
def toInt(): Int = version
def matches(version: Int): Boolean =
this.version == version
def matches(scopes: List[TokenScope]): Boolean =
this.scopes == scopes
object ScopesVersion:
val allScopesVersions: List[ScopesVersion] = List(
scopesVersion1
)
// Construct from a list of scopes
def apply(scopes: List[TokenScope]): Option[ScopesVersion] =
allScopesVersions.find(
(candidate: ScopesVersion) =>
candidate.matches(scopes)
)
// Construct from a version number
def apply(version: Int): Option[ScopesVersion] =
allScopesVersions.find(
(candidate: ScopesVersion) =>
candidate.matches(version)
)
val scopesVersion1: ScopesVersion =
new ScopesVersion:
val scopes = List(
TokenScope.UserReadChat,
TokenScope.BitsRead,
TokenScope.ChannelManageRaids
)
val version = 1