// Copyright © 2023 Kim Altintop <kim@eagain.io>
// SPDX-License-Identifier: GPL-2.0-only

use autosurgeon::{
    Hydrate,
    Reconcile,
};

mod patch;
pub use patch::Patch;

mod time;
pub use time::Timestamp;

#[cfg(test)]
mod tests;

#[derive(Clone, Debug, Reconcile, Hydrate)]
pub struct Discussion {
    pub id: u64,
    pub topic: String,
    pub tags: Vec<Tag>,
    pub entries: Vec<Entry>,
}

#[derive(Clone, Debug, Reconcile, Hydrate)]
pub struct Tag {
    pub text: String,
    pub color: String,
}

#[derive(Clone, Debug, Reconcile, Hydrate)]
pub struct Entry {
    pub meta: EntryMeta,
    pub kind: EntryKind,
}

#[derive(Clone, Debug, Reconcile, Hydrate)]
pub struct EntryMeta {
    pub identity: String,
    pub timestamp: Timestamp,
}

impl From<&str> for EntryMeta {
    fn from(identity: &str) -> Self {
        Self {
            identity: identity.to_owned(),
            timestamp: Timestamp::now(),
        }
    }
}

#[derive(Clone, Debug, Reconcile, Hydrate)]
pub enum EntryKind {
    Comment(String),
    Patch(Patch),
}

// TODO: Patch / hunk comments (i.e. code review)