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

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

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "audio_tracks")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: Uuid,
    pub album_id: Option<Uuid>,
    pub title: String,
    pub slug: String,
    pub audio_file_id: String,
    pub track_number: Option<i32>,
    pub duration: Option<i32>,
    pub featured: bool,
    pub published: bool,
    pub play_count: i32,
    pub created_at: DateTimeWithTimeZone,
    pub updated_at: DateTimeWithTimeZone,
    pub published_at: Option<DateTimeWithTimeZone>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::audio_albums::Entity",
        from = "Column::AlbumId",
        to = "super::audio_albums::Column::Id",
        on_update = "Cascade",
        on_delete = "SetNull"
    )]
    AudioAlbums,
    #[sea_orm(has_many = "super::audio_track_tags::Entity")]
    AudioTrackTags,
}

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

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

impl Related<super::audio_tags::Entity> for Entity {
    fn to() -> RelationDef {
        super::audio_track_tags::Relation::AudioTags.def()
    }
    fn via() -> Option<RelationDef> {
        Some(super::audio_track_tags::Relation::AudioTracks.def().rev())
    }
}
