io.github.pidoveproject.showdown.protocol.server.tournament.BattleState.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala-showdown-api_3 Show documentation
Show all versions of scala-showdown-api_3 Show documentation
A Scala wrapper of Pokemon Showdown's API
The newest version!
package io.github.pidoveproject.showdown.protocol.server.tournament
import zio.json.JsonDecoder
/**
* The state of a tournament battle
*/
enum BattleState:
/**
* The battle has not started yet but can be initiated.
*/
case Available
/**
* The participants are challenging themselves but the battle has not started yet.
*/
case Challenging
/**
* The participants are battling.
*/
case InProgress
/**
* The battle is finished.
*/
case Finished
/**
* The battle is not available.
*/
case Unavailable
object BattleState:
/**
* Get the [[BattleState]] by name.
*
* @param name the name of the state to retrieve
* @return the corresponding state
*/
def fromName(name: String): Option[BattleState] =
BattleState.values.find(_.toString equalsIgnoreCase name)
given JsonDecoder[BattleState] =
JsonDecoder
.string
.mapOrFail(BattleState.fromName(_).toRight("Invalid battle state"))