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

use super::ReviewState;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "pull_request_review")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub repo: RepoId,
    #[sea_orm(primary_key)]
    pub number: i64,
    #[sea_orm(primary_key)]
    pub reviewer: UserId,
    pub state: String,
    pub body: Option<String>,
    pub submitted_at: Option<DateTimeUtc>,
    pub created_at: DateTimeUtc,
    pub updated_at: DateTimeUtc,
}

impl Model {
    pub fn state_enum(&self) -> Result<ReviewState, &'static str> {
        self.state.parse()
    }
}

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

impl ActiveModelBehavior for ActiveModel {}
