use serde_json::Value;

/// Supported comparison operators used to describe a condition.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConditionOperator {
    Eq,
    Neq,
    Gt,
    Lt,
    In,
    Gte,
    Lte,
    Like,
    ILike,
    Is,
    Contains,
    Contained,
}

/// Represents a filter condition used for building SQL queries.
#[derive(Debug, Clone, PartialEq)]
pub struct Condition {
    pub column: String,
    pub operator: ConditionOperator,
    pub values: Vec<Value>,
    pub negated: bool,
    pub auto_cast_uuid_value_to_text: bool,
}

impl Condition {
    /// Builds an equality condition for the given column and value.
    pub fn eq(column: impl Into<String>, value: impl Into<Value>) -> Self {
        Self {
            column: column.into(),
            operator: ConditionOperator::Eq,
            values: vec![value.into()],
            negated: false,
            auto_cast_uuid_value_to_text: true,
        }
    }

    /// Builds a condition using the provided values and operator.
    pub fn new(
        column: impl Into<String>,
        operator: ConditionOperator,
        values: Vec<Value>,
        negated: bool,
    ) -> Self {
        Self {
            column: column.into(),
            operator,
            values,
            negated,
            auto_cast_uuid_value_to_text: true,
        }
    }

    /// Enables or disables automatic UUID value casting to text in predicates.
    pub fn with_uuid_value_text_cast(mut self, enabled: bool) -> Self {
        self.auto_cast_uuid_value_to_text = enabled;
        self
    }
}
