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

use automerge::{
    Automerge,
    Change,
    ChangeHash,
};

pub trait WritableStorage {
    type Error;

    fn store(
        &mut self,
        doc: &str,
        changes: impl IntoIterator<Item = Change>,
    ) -> Result<(), Self::Error>;
}

pub trait ReadableStorage {
    type Error;
    type Doc;

    fn load(&self, doc: &str) -> Result<Option<Automerge>, Self::Error>;
    fn exists(&self, doc: &str) -> Result<bool, Self::Error>;
    fn doc(&self, doc: &str) -> Result<Option<Self::Doc>, Self::Error>;
}

pub trait ChangeStore {
    type Error;

    fn write_change(&self, change: Change) -> Result<(), Self::Error>;
    fn get_change(&self, hash: &ChangeHash) -> Result<Option<Change>, Self::Error>;
    fn has_change(&self, hash: &ChangeHash) -> Result<bool, Self::Error>;
}