//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19

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

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "products")]
pub struct Model {
    pub created_at: DateTimeWithTimeZone,
    pub updated_at: DateTimeWithTimeZone,
    #[sea_orm(primary_key)]
    pub id: i32,
    pub name: String,
    #[sea_orm(unique)]
    pub slug: String,
    #[sea_orm(column_type = "Text", nullable)]
    pub description: Option<String>,
    #[sea_orm(column_type = "Text", nullable)]
    pub short_description: Option<String>,
    pub view_count: i32,
    pub published: bool,
    pub published_at: Option<DateTimeWithTimeZone>,
    pub category_id: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::categories::Entity",
        from = "Column::CategoryId",
        to = "super::categories::Column::Id",
        on_update = "NoAction",
        on_delete = "SetNull"
    )]
    Categories,
    #[sea_orm(has_many = "super::discount_profile_products::Entity")]
    DiscountProfileProducts,
    #[sea_orm(has_many = "super::order_items::Entity")]
    OrderItems,
    #[sea_orm(has_many = "super::product_images::Entity")]
    ProductImages,
    #[sea_orm(has_many = "super::product_product_tags::Entity")]
    ProductProductTags,
    #[sea_orm(has_many = "super::product_variants::Entity")]
    ProductVariants,
}

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

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

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

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

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

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

impl Related<super::product_tags::Entity> for Entity {
    fn to() -> RelationDef {
        super::product_product_tags::Relation::ProductTags.def()
    }
    fn via() -> Option<RelationDef> {
        Some(super::product_product_tags::Relation::Products.def().rev())
    }
}
