//! Enumerates the errors that can occur.
use std::io;

use sqlx::Error as SqlxError;
use thiserror::Error;
use toml::de::Error as TomlError;

#[derive(Error, Debug)]
pub enum PtError {
    #[error("database error: `{0}`")]
    DatabaseError(String),
    #[error("primary key not found")]
    PrimaryKeyNotFound,
    #[error("metadata is available for tables only")]
    MetadataAvailableForRelationOnly,
    #[error("cannot fetch record count")]
    CannotFetchRecordCount,
    #[error("cannot fetch table data")]
    CannotFetchTableData,
    #[error("sqlx error: `{0}`")]
    SqlxError(#[from] SqlxError),
    #[error("array items not all same type")]
    ArrayItemsNotSameType,
    #[error("insert or update abandoned by user")]
    Abandoned,
    #[error("Io error")]
    IoError(#[from] io::Error),
    #[error("toml error")]
    TomlError(#[from] TomlError),
    #[error("index error")]
    IndexError,
    #[error("no current relation")]
    NoCurrentRelation,
    #[error("not implemented")]
    NotImplemented,
}
