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

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "repo_upstream")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,
    #[sea_orm(column_name = "repo_uuid")]
    pub repo: RepoId,
    pub source_url: String,
    pub direction: String,
    pub schedule_cron: Option<String>,
    pub last_run_at: Option<DateTimeUtc>,
    pub next_run_at: Option<DateTimeUtc>,
    pub status: String,
    pub created_at: DateTimeUtc,
    pub updated_at: DateTimeUtc,
}

impl Model {
    pub fn direction_enum(&self) -> Result<super::SyncDirection, &'static str> {
        self.direction.parse()
    }
    pub fn status_enum(&self) -> Result<super::SyncStatus, &'static str> {
        self.status.parse()
    }
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
