use sea_query::*;
use std::fmt::Write;

#[derive(Debug, Default, Clone, Copy)]
pub struct ClickhouseQueryBuilder;

impl QuotedBuilder for ClickhouseQueryBuilder {
    fn quote(&self) -> Quote {
        MysqlQueryBuilder.quote()
    }
}

impl EscapeBuilder for ClickhouseQueryBuilder {
    fn write_escaped(&self, buffer: &mut impl Write, string: &str) {
        for c in string.chars() {
            match c {
                '\\' => buffer.write_str("\\\\"),
                '\'' => buffer.write_str("\\'"),
                '\0' => buffer.write_str("\\0"),
                '\n' => buffer.write_str("\\n"),
                '\r' => buffer.write_str("\\r"),
                '\t' => buffer.write_str("\\t"),
                _ => buffer.write_char(c),
            }
            .unwrap()
        }
    }
}

impl TableRefBuilder for ClickhouseQueryBuilder {}

impl OperLeftAssocDecider for ClickhouseQueryBuilder {
    fn well_known_left_associative(&self, op: &BinOper) -> bool {
        MysqlQueryBuilder.well_known_left_associative(op)
    }
}

impl PrecedenceDecider for ClickhouseQueryBuilder {
    fn inner_expr_well_known_greater_precedence(&self, inner: &Expr, outer_oper: &Oper) -> bool {
        MysqlQueryBuilder.inner_expr_well_known_greater_precedence(inner, outer_oper)
    }
}

impl GenericBuilder for ClickhouseQueryBuilder {}
impl SchemaBuilder for ClickhouseQueryBuilder {}
