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

use sea_orm::entity::prelude::*;
use serde::Serialize;

/// State of a ticket
#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize)]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(16))")]
pub enum State {
    /// Open - needs doing
    #[sea_orm(string_value = "open")]
    Open,
    /// Closed - done or won't do
    #[sea_orm(string_value = "closed")]
    Closed,
}

#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize)]
#[sea_orm(table_name = "tickets")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,
    #[sea_orm(unique)]
    pub uuid: Uuid,
    pub repository_id: i64,
    /// Who opened it. The owner of the repository is not assumed to be the
    /// one who did: a ticket is usually somebody else's complaint.
    /// Nullable: remote actors can create tickets via federation.
    pub creator_id: Option<i64>,
    /// Remote actor who created this ticket (for federated tickets).
    /// Exactly one of creator_id or remote_actor_id is set.
    pub remote_actor_id: Option<i64>,
    /// The inbound Offer activity id, for idempotency on federation.
    pub remote_offer_id: Option<String>,
    /// The activity URL of the last emitted/accepted Resolve, for Undo(Resolve) correlation.
    pub resolve_activity_url: Option<String>,
    /// The ticket's number within its repository, which is what its address
    /// holds. Counted by `repositories.next_ticket_number` rather than by
    /// the tickets that still exist, so it is never given out twice.
    pub number: i64,
    pub summary: String,
    pub description: Option<String>,
    /// Whether the ticket is open or closed - its state rather than a label.
    pub state: State,
    pub created_at: DateTimeWithTimeZone,
    pub updated_at: DateTimeWithTimeZone,
}

impl ActiveModelBehavior for ActiveModel {}
