/*
 * Copyright(c) 2024-2026 China Telecom Cloud Technologies Co., Ltd. All rights
 * reserved. ctscat is licensed under Mulan PSL v2. You can use this software
 * according to the terms and conditions of the Mulan PSL V2. You may obtain a
 * copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  See the Mulan PSL v2 for
 * more details.
 */

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

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

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, Default)]
#[sea_orm(table_name = "packages")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    #[sea_orm(unique)]
    pub name: String,
    pub level: i32,
    pub sync_interval_hours: i32,
    pub l0_repo_url: Option<String>,
    pub description: Option<String>,
    pub created_at: DateTimeUtc,
    pub updated_at: DateTimeUtc,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(has_many = "super::tracking::Entity")]
    Tracking,
    #[sea_orm(has_many = "super::l0_commits::Entity")]
    L0Commits,
    #[sea_orm(has_many = "super::backport_candidates::Entity")]
    BackportCandidates,
}

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

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

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

impl ActiveModelBehavior for ActiveModel {}