// SPDX-License-Identifier: Apache-2.0

//! Spatial scalar function registrations.

use nodedb_types::columnar::ColumnType;

use crate::functions::arg_types;
use crate::functions::registry::{FunctionCategory::Scalar, FunctionMeta, SearchTrigger};

use super::super::helpers::{m, no_trigger};

pub(super) fn spatial_functions() -> Vec<FunctionMeta> {
    vec![
        m(
            "st_geohash",
            Scalar,
            2,
            3,
            no_trigger(),
            Some(ColumnType::String),
            arg_types::ST_GEOHASH_ARGS,
        ),
        m(
            "st_geohashdecode",
            Scalar,
            1,
            1,
            no_trigger(),
            None,
            arg_types::ST_GEOHASHDECODE_ARGS,
        ),
        m(
            "h3_latlngtocell",
            Scalar,
            3,
            3,
            no_trigger(),
            Some(ColumnType::String),
            arg_types::H3_LATLNGTOCELL_ARGS,
        ),
        m(
            "h3_celltolatlng",
            Scalar,
            1,
            1,
            no_trigger(),
            None,
            arg_types::H3_CELLTOLATLNG_ARGS,
        ),
        m(
            "st_dwithin",
            Scalar,
            3,
            3,
            SearchTrigger::SpatialDWithin,
            Some(ColumnType::Bool),
            arg_types::SPATIAL_3_ARGS,
        ),
        m(
            "st_contains",
            Scalar,
            2,
            2,
            SearchTrigger::SpatialContains,
            Some(ColumnType::Bool),
            arg_types::SPATIAL_2_ARGS,
        ),
        m(
            "st_intersects",
            Scalar,
            2,
            2,
            SearchTrigger::SpatialIntersects,
            Some(ColumnType::Bool),
            arg_types::SPATIAL_2_ARGS,
        ),
        m(
            "st_within",
            Scalar,
            2,
            2,
            SearchTrigger::SpatialWithin,
            Some(ColumnType::Bool),
            arg_types::SPATIAL_2_ARGS,
        ),
        m(
            "st_distance",
            Scalar,
            2,
            2,
            no_trigger(),
            Some(ColumnType::Float64),
            arg_types::SPATIAL_2_ARGS,
        ),
        m(
            "st_point",
            Scalar,
            2,
            2,
            no_trigger(),
            Some(ColumnType::Geometry),
            arg_types::ST_POINT_ARGS,
        ),
        m(
            "st_intersection",
            Scalar,
            2,
            2,
            no_trigger(),
            Some(ColumnType::Geometry),
            arg_types::SPATIAL_2_ARGS,
        ),
        m(
            "st_union",
            Scalar,
            2,
            2,
            no_trigger(),
            Some(ColumnType::Geometry),
            arg_types::SPATIAL_2_ARGS,
        ),
        m(
            "st_buffer",
            Scalar,
            2,
            3,
            no_trigger(),
            Some(ColumnType::Geometry),
            arg_types::ST_BUFFER_ARGS,
        ),
        m(
            "st_envelope",
            Scalar,
            1,
            1,
            no_trigger(),
            Some(ColumnType::Geometry),
            arg_types::ST_ENVELOPE_ARGS,
        ),
    ]
}
