use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use std::fmt;
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel)]
#[sea_orm(table_name = "move_struct_ability")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(indexed)]
pub struct_id: i32,
#[sea_orm(indexed)]
pub ability: MoveAbility,
#[sea_orm(belongs_to, from = "struct_id", to = "id")]
pub move_struct: HasOne<super::move_struct::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
EnumIter,
DeriveActiveEnum,
Serialize,
Deserialize,
)]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(8))")]
pub enum MoveAbility {
#[sea_orm(string_value = "copy")]
Copy,
#[sea_orm(string_value = "drop")]
Drop,
#[sea_orm(string_value = "store")]
Store,
#[sea_orm(string_value = "key")]
Key,
}
impl MoveAbility {
pub fn as_str(&self) -> &'static str {
match self {
Self::Copy => "copy",
Self::Drop => "drop",
Self::Store => "store",
Self::Key => "key",
}
}
pub fn parse(token: &str) -> Option<Self> {
match token.trim().to_ascii_lowercase().as_str() {
"copy" => Some(Self::Copy),
"drop" => Some(Self::Drop),
"store" => Some(Self::Store),
"key" => Some(Self::Key),
_ => None,
}
}
pub fn canonical_order(&self) -> u8 {
match self {
Self::Copy => 0,
Self::Drop => 1,
Self::Store => 2,
Self::Key => 3,
}
}
}
impl fmt::Display for MoveAbility {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}