/*
 * Copyright(c) 2024-2026 China Telecom Cloud Technologies Co., Ltd. All rights
 * reserved. track-system 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)]
#[sea_orm(table_name = "spec_changes")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub commit_record_id: i32,
    pub old_snapshot_id: Option<i32>,
    pub new_snapshot_id: i32,
    pub version_changed: bool,
    pub old_version: Option<String>,
    pub new_version: Option<String>,
    pub release_changed: bool,
    pub old_release: Option<String>,
    pub new_release: Option<String>,
    pub sources_changed: bool,
    pub sources_added: i32,
    pub sources_removed: i32,
    pub sources_modified: i32,
    pub patches_changed: bool,
    pub patches_added: i32,
    pub patches_removed: i32,
    pub patches_modified: i32,
    pub changelog_entries_added: i32,
    pub created_at: DateTimeUtc,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::l1_commit_records::Entity",
        from = "Column::CommitRecordId",
        to = "super::l1_commit_records::Column::Id",
        on_update = "NoAction",
        on_delete = "Cascade"
    )]
    CommitRecords,
    #[sea_orm(
        belongs_to = "super::spec_snapshots::Entity",
        from = "Column::NewSnapshotId",
        to = "super::spec_snapshots::Column::Id",
        on_update = "NoAction",
        on_delete = "Cascade"
    )]
    SpecSnapshots2,
    #[sea_orm(
        belongs_to = "super::spec_snapshots::Entity",
        from = "Column::OldSnapshotId",
        to = "super::spec_snapshots::Column::Id",
        on_update = "NoAction",
        on_delete = "SetNull"
    )]
    SpecSnapshots1,
}

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

impl ActiveModelBehavior for ActiveModel {}