use sea_query::*;

use crate::ClickhouseQueryBuilder;

impl IndexBuilder for ClickhouseQueryBuilder {
    fn prepare_index_create_statement(
        &self,
        create: &IndexCreateStatement,
        sql: &mut impl SqlWriter,
    ) {
        MysqlQueryBuilder.prepare_index_create_statement(create, sql);
    }

    fn prepare_table_ref_index_stmt(&self, table_ref: &TableRef, sql: &mut impl SqlWriter) {
        MysqlQueryBuilder.prepare_table_ref_index_stmt(table_ref, sql);
    }

    fn prepare_index_drop_statement(&self, drop: &IndexDropStatement, sql: &mut impl SqlWriter) {
        MysqlQueryBuilder.prepare_index_drop_statement(drop, sql);
    }

    fn prepare_index_type(&self, col_index_type: &Option<IndexType>, sql: &mut impl SqlWriter) {
        if let Some(index_type) = col_index_type {
            sql.write_str(" TYPE ").unwrap();
            match index_type {
                IndexType::BTree => sql.write_str("minmax"),
                IndexType::FullText => sql.write_str("tokenbf_v1(10240, 3, 0)"),
                IndexType::Hash => sql.write_str("set(0)"),
                IndexType::Custom(custom) => sql.write_str(&custom.to_string()),
                _ => sql.write_str(""),
            }
            .unwrap()
        }
    }

    fn prepare_index_prefix(&self, _create: &IndexCreateStatement, _sql: &mut impl SqlWriter) {}
}
