//! `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 = "product_variants")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub created_at: DateTimeWithTimeZone,
    pub updated_at: DateTimeWithTimeZone,
    pub product_id: i32,
    pub label: String,
    pub position: i32,
    pub sku: Option<String>,
    pub stock: Option<i32>,
    pub price_cents: i64,
    pub sale_price_cents: Option<i64>,
    pub business_sale_price_cents: Option<i64>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(has_many = "super::account_cart_items::Entity")]
    AccountCartItems,
    #[sea_orm(has_many = "super::account_product_prices::Entity")]
    AccountProductPrices,
    #[sea_orm(has_many = "super::account_product_resolutions::Entity")]
    AccountProductResolutions,
    #[sea_orm(has_many = "super::order_items::Entity")]
    OrderItems,
    #[sea_orm(
        belongs_to = "super::products::Entity",
        from = "Column::ProductId",
        to = "super::products::Column::Id",
        on_update = "NoAction",
        on_delete = "Cascade"
    )]
    Products,
}

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

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

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

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

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