use super::Registry;
use super::FunctionMeta;

pub mod arabic;
pub mod char_fn;
pub mod clean;
pub mod code_fn;
pub mod concatenate;
pub mod dollar;
pub mod exact;
pub mod find;
pub mod findb;
pub mod fixed;
pub mod left;
pub mod leftb;
pub mod len;
pub mod lenb;
pub mod lower;
pub mod mid;
pub mod midb;
pub mod replace;
pub mod replaceb;
pub mod rept;
pub mod right;
pub mod rightb;
pub mod roman;
pub mod searchb;
pub mod substitute;
pub mod t_fn;
pub mod text_fn;
pub mod proper;
pub mod regexextract;
pub mod regexmatch;
pub mod regexreplace;
pub mod search;
pub mod trim;
pub mod upper;
pub mod value_fn;
pub mod asc;
pub mod join_fn;
pub mod split_fn;
pub mod textjoin;

pub fn register_text(registry: &mut Registry) {
    registry.register_eager("LEFT",        left::left_fn,              FunctionMeta { category: "text", signature: "LEFT(text, num_chars)",                      description: "Left portion of a string" });
    registry.register_eager("MID",         mid::mid_fn,                FunctionMeta { category: "text", signature: "MID(text, start, num_chars)",                description: "Substring from middle of text" });
    registry.register_eager("RIGHT",       right::right_fn,            FunctionMeta { category: "text", signature: "RIGHT(text, num_chars)",                     description: "Right portion of a string" });
    registry.register_eager("LEN",         len::len_fn,                FunctionMeta { category: "text", signature: "LEN(text)",                                  description: "Number of characters in text" });
    registry.register_eager("LOWER",       lower::lower_fn,            FunctionMeta { category: "text", signature: "LOWER(text)",                                description: "Convert to lowercase" });
    registry.register_eager("UPPER",       upper::upper_fn,            FunctionMeta { category: "text", signature: "UPPER(text)",                                description: "Convert to uppercase" });
    registry.register_eager("TRIM",        trim::trim_fn,              FunctionMeta { category: "text", signature: "TRIM(text)",                                 description: "Remove extra whitespace" });
    registry.register_eager("CONCATENATE", concatenate::concatenate_fn,FunctionMeta { category: "text", signature: "CONCATENATE(value1,...)",                    description: "Concatenate values (legacy)" });
    registry.register_eager("FIND",        find::find_fn,              FunctionMeta { category: "text", signature: "FIND(find_text, within_text, start)",        description: "Case-sensitive position search" });
    registry.register_eager("SUBSTITUTE",  substitute::substitute_fn,  FunctionMeta { category: "text", signature: "SUBSTITUTE(text, old, new, instance)",       description: "Replace occurrences of a substring" });
    registry.register_eager("REPLACE",     replace::replace_fn,        FunctionMeta { category: "text", signature: "REPLACE(text, start, num_chars, new_text)",  description: "Replace portion of text" });
    registry.register_eager("TEXT",        text_fn::text_fn,           FunctionMeta { category: "text", signature: "TEXT(value, format)",                        description: "Format number as text" });
    registry.register_eager("VALUE",       value_fn::value_fn,         FunctionMeta { category: "text", signature: "VALUE(text)",                                description: "Convert text to number" });
    registry.register_eager("REPT",        rept::rept_fn,              FunctionMeta { category: "text", signature: "REPT(text, number_times)",                   description: "Repeat text N times" });
    registry.register_eager("CHAR",        char_fn::char_fn,           FunctionMeta { category: "text", signature: "CHAR(number)",                               description: "Character from ASCII/Unicode code" });
    registry.register_eager("UNICHAR",     char_fn::unichar_fn,        FunctionMeta { category: "text", signature: "UNICHAR(number)",                            description: "Unicode character from code point" });
    registry.register_eager("CODE",        code_fn::code_fn,           FunctionMeta { category: "text", signature: "CODE(text)",                                 description: "Numeric code of first character" });
    registry.register_eager("UNICODE",     code_fn::unicode_fn,        FunctionMeta { category: "text", signature: "UNICODE(text)",                              description: "Unicode code point of first character" });
    registry.register_eager("EXACT",       exact::exact_fn,            FunctionMeta { category: "text", signature: "EXACT(text1, text2)",                        description: "Case-sensitive string comparison" });
    registry.register_eager("T",           t_fn::t_fn,                 FunctionMeta { category: "text", signature: "T(value)",                                   description: "Return text if value is text, else empty string" });
    registry.register_eager("PROPER",      proper::proper_fn,          FunctionMeta { category: "text", signature: "PROPER(text)",                                  description: "Capitalize first letter of each word" });
    registry.register_eager("SEARCH",      search::search_fn,          FunctionMeta { category: "text", signature: "SEARCH(find_text, within_text, [start_num])",   description: "Case-insensitive search with wildcards" });
    registry.register_eager("ARABIC",      arabic::arabic_fn,          FunctionMeta { category: "text", signature: "ARABIC(roman_text)",                             description: "Convert Roman numeral to integer" });
    registry.register_eager("ROMAN",       roman::roman_fn,            FunctionMeta { category: "text", signature: "ROMAN(number)",                                  description: "Convert integer to Roman numeral string" });
    registry.register_eager("CLEAN",       clean::clean_fn,            FunctionMeta { category: "text", signature: "CLEAN(text)",                                    description: "Remove non-printable characters from text" });
    registry.register_eager("FIXED",       fixed::fixed_fn,            FunctionMeta { category: "text", signature: "FIXED(number, [decimals], [no_commas])",         description: "Format number as text with fixed decimal places" });
    registry.register_eager("DOLLAR",      dollar::dollar_fn,          FunctionMeta { category: "text", signature: "DOLLAR(number, [decimals])",                     description: "Format number as currency text" });
    registry.register_eager("LEFTB",       leftb::leftb_fn,            FunctionMeta { category: "text", signature: "LEFTB(text, num_bytes)",                          description: "Left N bytes of text" });
    registry.register_eager("RIGHTB",      rightb::rightb_fn,          FunctionMeta { category: "text", signature: "RIGHTB(text, num_bytes)",                         description: "Right N bytes of text" });
    registry.register_eager("LENB",        lenb::lenb_fn,              FunctionMeta { category: "text", signature: "LENB(text)",                                      description: "Number of bytes in text" });
    registry.register_eager("MIDB",        midb::midb_fn,              FunctionMeta { category: "text", signature: "MIDB(text, start_byte, num_bytes)",               description: "Substring by byte position" });
    registry.register_eager("FINDB",       findb::findb_fn,            FunctionMeta { category: "text", signature: "FINDB(find_text, within_text, [start_num])",      description: "Case-sensitive byte-position search" });
    registry.register_eager("REPLACEB",    replaceb::replaceb_fn,      FunctionMeta { category: "text", signature: "REPLACEB(text, start_byte, num_bytes, new_text)", description: "Replace portion of text by byte position" });
    registry.register_eager("SEARCHB",     searchb::searchb_fn,        FunctionMeta { category: "text", signature: "SEARCHB(find_text, within_text, [start_num])",    description: "Case-insensitive byte-position search with wildcards" });
    registry.register_eager("ASC",         asc::asc_fn,                FunctionMeta { category: "text", signature: "ASC(text)",                                        description: "Convert full-width chars to half-width" });
    registry.register_eager("JOIN",        join_fn::join_fn,           FunctionMeta { category: "text", signature: "JOIN(delimiter, value1, ...)",                     description: "Join values with delimiter" });
    registry.register_eager("SPLIT",       split_fn::split_fn,         FunctionMeta { category: "text", signature: "SPLIT(text, delimiter)",                           description: "Split text into array by delimiter" });
    registry.register_eager("TEXTJOIN",    textjoin::textjoin_fn,      FunctionMeta { category: "text", signature: "TEXTJOIN(delimiter, ignore_empty, value1, ...)",   description: "Join values with delimiter, optionally skip empty" });
    registry.register_eager("REGEXMATCH",   regexmatch::regexmatch_fn,     FunctionMeta { category: "text", signature: "REGEXMATCH(text, pattern)",               description: "True if text matches regex pattern" });
    registry.register_eager("REGEXEXTRACT", regexextract::regexextract_fn, FunctionMeta { category: "text", signature: "REGEXEXTRACT(text, pattern)",             description: "Extract first regex match from text" });
    registry.register_eager("REGEXREPLACE", regexreplace::regexreplace_fn, FunctionMeta { category: "text", signature: "REGEXREPLACE(text, pattern, replacement)", description: "Replace regex matches in text" });
}
