use async_trait::async_trait;
use std::{collections::HashMap, fmt::Debug, num::ParseIntError};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum StoreError {
#[error("Fail to get value from store")]
GetError,
#[error("Fail to set value in store")]
SetError,
#[error("Fail to delete value from store")]
DeleteError,
#[error("Fail to get many values from store")]
GetManyError,
#[error("Fail to set many values in store")]
SetManyError,
#[error("Fail to delete many values from store")]
DeleteManyError,
#[cfg(feature = "sqlite")]
#[error("SQLite error: {0}")]
SQLite(#[from] sqlx::Error),
#[error("Parse error: {0}")]
Parse(#[from] ParseIntError),
#[error("Custom error: {0:?}")]
Custom(Box<dyn std::error::Error + Send + Sync + 'static>),
}
#[async_trait]
pub trait Store: Send + Sync + Debug {
fn id(&self) -> String;
async fn get(&self, key: &str) -> Result<Option<String>, StoreError>;
async fn get_many(&self, keys: Vec<&str>) -> Result<HashMap<String, String>, StoreError>;
async fn set(&self, key: &str, value: &str) -> Result<(), StoreError>;
async fn set_many(&self, entries: HashMap<String, String>) -> Result<(), StoreError>;
async fn delete(&self, key: &str) -> Result<(), StoreError>;
async fn delete_many(&self, keys: Vec<&str>) -> Result<(), StoreError>;
}