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

use autosurgeon::{
    hydrate,
    reconcile,
};

use super::*;

#[test]
fn play() {
    let mut doc = automerge::AutoCommit::new();
    reconcile(
        &mut doc,
        &Discussion {
            id: 0,
            topic: "test".into(),
            tags: vec![],
            entries: vec![],
        },
    )
    .unwrap();

    let mut doc2 = doc.fork().with_actor(automerge::ActorId::random());
    let mut disc2: Discussion = hydrate(&doc2).unwrap();
    disc2.entries.push(Entry {
        meta: EntryMeta::from("Dylan"),
        kind: EntryKind::Comment("Yo".into()),
    });
    reconcile(&mut doc2, &disc2).unwrap();

    let mut doc1 = doc.fork().with_actor(automerge::ActorId::random());
    let mut disc1: Discussion = hydrate(&doc1).unwrap();
    disc1.entries.push(Entry {
        meta: EntryMeta::from("dave"),
        kind: EntryKind::Comment("hey".into()),
    });
    reconcile(&mut doc1, &disc1).unwrap();

    doc.merge(&mut doc1).unwrap();
    doc.merge(&mut doc2).unwrap();

    let merged: Discussion = hydrate(&doc).unwrap();
    println!("{merged:#?}");

    println!("Changes:");
    for change in doc.get_changes(&[]) {
        println!("{change:#?}");
    }
}