use super::{list::DuplicateEntry, ColumnConfig};
use crate::TableConfig;
use std::convert::Infallible;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum ConfigError {
    #[error("Further qualification to {0} is not possible with qualifer {1}")]
    UnexpectedQualifier(String, String),
    #[error("'{0}' is not a valid path")]
    InvalidPath(String),
    #[error("Scope qualifiers do no match")]
    MismatchedScope,
    #[error(transparent)]
    Infallible(#[from] Infallible),
    #[error(transparent)]
    DuplicateRelation(#[from] DuplicateEntry<TableConfig>),
    #[error(transparent)]
    DuplicateField(#[from] DuplicateEntry<ColumnConfig>),
    #[error("ste_vec index on {table}.{column} requires plaintext_type: json (found {found_plaintext_type})")]
    SteVecRequiresJson {
        table: String,
        column: String,
        found_plaintext_type: String,
    },
    #[error("unsupported config version: {version} (expected {expected})")]
    UnsupportedVersion { version: u32, expected: u32 },
    #[error("match index on {table}.{column} requires plaintext_type: text (found {found_plaintext_type})")]
    MatchRequiresText {
        table: String,
        column: String,
        found_plaintext_type: String,
    },
    #[error("Failed to parse encryption config: {0}")]
    ParseError(String),
}
