use crate::base::{database::ColumnType, math::decimal::DecimalError};
use proof_of_sql_parser::intermediate_ast::{BinaryOperator, UnaryOperator};
use thiserror::Error;
#[derive(Error, Debug, PartialEq, Eq)]
pub enum ColumnOperationError {
#[error("Columns have different lengths: {0} != {1}")]
DifferentColumnLength(usize, usize),
#[error("{operator:?}(lhs: {left_type:?}, rhs: {right_type:?}) is not supported")]
BinaryOperationInvalidColumnType {
operator: BinaryOperator,
left_type: ColumnType,
right_type: ColumnType,
},
#[error("{operator:?}(operand: {operand_type:?}) is not supported")]
UnaryOperationInvalidColumnType {
operator: UnaryOperator,
operand_type: ColumnType,
},
#[error("Overflow in integer operation: {0}")]
IntegerOverflow(String),
#[error("Division by zero")]
DivisionByZero,
#[error(transparent)]
DecimalConversionError(#[from] DecimalError),
}
pub type ColumnOperationResult<T> = std::result::Result<T, ColumnOperationError>;