use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "plugin_market_reviews")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: Uuid,
    pub tenant_id: Uuid,
    pub user_id: Uuid,
    pub market_entry_id: Uuid,
    pub rating: i32,
    pub review_text: Option<String>,
    pub created_at: DateTimeUtc,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::market_entry::Entity",
        from = "Column::MarketEntryId",
        to = "super::market_entry::Column::Id"
    )]
    MarketEntry,
}

impl Related<super::market_entry::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::MarketEntry.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}
