pub mod caldav;
pub mod local;
pub use caldav::CaldavStore;
pub use local::LocalStore;
use std::error::Error;
use aimcal_ical::{VEvent, VTodo};
use async_trait::async_trait;
use crate::{EventPatch, TodoPatch};
pub type StoreError = Box<dyn Error + Send + Sync>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SyncResult {
pub created: usize,
pub updated: usize,
pub deleted: usize,
}
#[async_trait]
pub trait Store: Send + Sync {
async fn create_event(&self, uid: &str, event: &VEvent<String>) -> Result<String, StoreError>;
async fn get_event(&self, uid: &str) -> Result<VEvent<String>, StoreError>;
async fn update_event(
&self,
uid: &str,
patch: &EventPatch,
) -> Result<VEvent<String>, StoreError>;
async fn delete_event(&self, uid: &str) -> Result<(), StoreError>;
async fn create_todo(&self, uid: &str, todo: &VTodo<String>) -> Result<String, StoreError>;
async fn get_todo(&self, uid: &str) -> Result<VTodo<String>, StoreError>;
async fn update_todo(&self, uid: &str, patch: &TodoPatch) -> Result<VTodo<String>, StoreError>;
async fn delete_todo(&self, uid: &str) -> Result<(), StoreError>;
async fn list_events(&self) -> Result<Vec<(String, VEvent<String>)>, StoreError>;
async fn list_todos(&self) -> Result<Vec<(String, VTodo<String>)>, StoreError>;
async fn uid_exists(&self, uid: &str) -> Result<bool, StoreError>;
fn calendar_id(&self) -> &str;
async fn sync_cache(&self) -> Result<SyncResult, StoreError>;
}