//! Main entry point for IR to SQL translation.
//!
//! This module provides the top-level API for translating Hamelin IR to SQL.

use hamelin_lib::err::TranslationErrors;
use hamelin_lib::sql::statement::Statement;

use hamelin_translation::IRStatement;

use crate::command::CommandTranslator;
use crate::statement::translate_statement;
use crate::TranslationRegistry;

/// Translate an IR statement to SQL using a dialect-specific translator.
///
/// This is the primary entry point for IR-to-SQL translation. It uses
/// the default `TranslationRegistry` which includes all built-in function
/// translations.
///
/// # Example
///
/// ```ignore
/// use hamelin_trino::TrinoCommandTranslator;
///
/// let ir = lower(typed_statement)?;
/// let sql_statement = translate(&ir, &TrinoCommandTranslator)?;
/// let sql_string = sql_statement.to_string();
/// ```
pub fn translate<T: CommandTranslator>(
    ir: &IRStatement,
    translator: &T,
) -> Result<Statement, TranslationErrors> {
    let registry = TranslationRegistry::default();
    translate_statement(ir, &registry, translator)
}
