//! Translation implementations for window functions

use crate::utils::{direct_function_translation, function_translation_respecting_ignore_nulls};
use crate::TranslationRegistry;
use hamelin_lib::func::defs::{
    CumeDist, DenseRank, FirstValue, Lag, LastValue, Lead, NthValue, PercentRank, Rank, RowNumber,
};

/// Register all window function translations.
pub fn register(registry: &mut TranslationRegistry) {
    // row_number() - pass through
    registry.register::<RowNumber>(direct_function_translation);

    // rank() - pass through
    registry.register::<Rank>(direct_function_translation);

    // dense_rank() - pass through
    registry.register::<DenseRank>(direct_function_translation);

    // lag(expression, offset, ignore_nulls) - respects ignore_nulls
    registry.register::<Lag>(function_translation_respecting_ignore_nulls);

    // lead(expression, offset, ignore_nulls) - respects ignore_nulls
    registry.register::<Lead>(function_translation_respecting_ignore_nulls);

    // first_value(expression, ignore_nulls) - respects ignore_nulls
    registry.register::<FirstValue>(function_translation_respecting_ignore_nulls);

    // last_value(expression, ignore_nulls) - respects ignore_nulls
    registry.register::<LastValue>(function_translation_respecting_ignore_nulls);

    // nth_value(expression, n, ignore_nulls) - respects ignore_nulls
    registry.register::<NthValue>(function_translation_respecting_ignore_nulls);

    // cume_dist() - pass through
    registry.register::<CumeDist>(direct_function_translation);

    // percent_rank() - pass through
    registry.register::<PercentRank>(direct_function_translation);
}
