use thiserror::Error;
use url::ParseError;
use crate::{NoteID, Revision};
#[derive(Error, Debug)]
pub enum NoteStoreError {
#[error("note `{0}` doesn't exist")]
NoteNotExist(NoteID),
#[error("note `{0}` already exists")]
NoteIDConflict(NoteID),
#[error("revision`{1}` of note `{0}` doesn't exist")]
RevisionNotExist(NoteID, Revision),
#[error("io error")]
IOError(#[from] std::io::Error),
#[error("serde error")]
SerdeError(#[from] serde_json::Error),
#[error("attempt to update non-current revision `{1}` of note `{0}`")]
UpdateOldRevision(NoteID, Revision),
#[error("attempt to delete non-current revision `{1}` of note `{0}`")]
DeleteOldRevision(NoteID, Revision),
#[error("inconsistency detected: note `{1}` is not a child of note `{0}`")]
NotAChild(NoteID, NoteID),
#[error("cannot append note `{1}` to note `{0}`, because note `{0}` is not the last note in a sequence")]
ExistingNext(NoteID, NoteID),
#[error("cannot delete note `{0}`, because it has branches")]
HasBranches(NoteID),
#[error("cannot delete note `{0}`, because other notes refer to it")]
HasReferences(NoteID),
#[error("note cannot be parsed: `{0}`")]
ParseError(String),
#[error("PostgreSQL error")]
PostgreSQLError(#[from] sqlx::Error),
#[error("error processing note inner")]
NoteInnerError(String),
#[error("id or revision is not UUID")]
NotUuid(String),
}
#[derive(Error, Debug)]
pub enum URLParseError {
#[error("Not a valid URL")]
NotAURL(#[from] ParseError),
#[error("URL scheme `{0}` not supported")]
WrongScheme(String),
#[error("The URL cannot be a base")]
CannotBeABase,
#[error("Syntax error: `{0}`")]
SyntaxError(String),
}