\ProvidesExplPackage{numbersets}{2024-10-15}{v0.2.0}{A package for displaying number sets with customizable typefaces}

% List of properties to store style commands
\prop_new:N \g_numbersets_styles_prop

% Global default style for the package
\cs_new:Nn \g_numbersets_default_style_tl: { bb }

% Presets for typefaces
\prop_put:Nnn \g_numbersets_styles_prop { bb } { \symbb }
\prop_put:Nnn \g_numbersets_styles_prop { bfup } { \symbfup }
\prop_put:Nnn \g_numbersets_styles_prop { bfit } { \symbfit }

% Options for package
\keys_define:nn { numbersets }
{
	style .tl_set:N = \g_numbersets_default_style_tl,
	style .initial:n = bb,
}

\ProcessKeyOptions

% Validation for property
\cs_new_protected:Npn \numbersets_check_style:n #1
{
	\prop_if_in:NnTF \g_numbersets_styles_prop { #1 }
	{ }
	{
		\msg_error:nnn { numbersets } { unknown-style } { #1 }
	}
}

% Error message for unknown options
\msg_new:nnn { numbersets } { unknown-style }
{
	The~style~'#1'~is~not~declared.
}

% Command to declare (or overwrite) styles
\NewDocumentCommand{\DeclareNumberSetStyle}{ m m }
{
	\prop_put:Nnn \g_numbersets_styles_prop { #1 } { #2 }
}

% Command for setup global option 
\NewDocumentCommand{\SetupNumberSetsOptions}{ m }
{
	\keys_set:nn { numbersets } { #1 }
}

% Function to apply the style command
\cs_new_protected:Npn \numbersets_apply_style:n #1
{
	\prop_get:NnNTF \g_numbersets_styles_prop { #1 } \l_tmpa_tl
	{
		\use:n { \l_tmpa_tl }
	}
	{
		\msg_error:nnn { numbersets } { unknown-style } { #1 }
	}
}

% Store the style identifer of the \numberset command as a local variable
\cs_new:Nn \l_numbersets_style_tl: { }

% Options for the \numberset command
\keys_define:nn { numberset }
{
	style .tl_set:N = \l_numbersets_style_tl,
}

% Command to display the set symbol with custom typefaces
\NewDocumentCommand{\NumberSet}{ O{} m }
{
	\group_begin:
	\keys_set:nn { numberset } { #1 }
	\tl_if_empty:VTF \l_numbersets_style_tl
	{
		\tl_set_eq:NN \l_numbersets_style_tl \g_numbersets_default_style_tl
	}
	{}
	\expandafter\numbersets_apply_style:n \expandafter{ \l_numbersets_style_tl }
	{ #2 }
	\group_end:
}

% Command to declare custom commands for set composed of numbers
\NewDocumentCommand{\DeclareNumberSetCommand}{ m m }
{
	\NewDocumentCommand{#1}
	{o}
	{
		\IfValueTF{##1}
		{
			\NumberSet[##1]{#2}
		}
		{
			\NumberSet{#2}
		}
	}
}

% Presets for some sets composed of numbers

% Natural numbers
\DeclareNumberSetCommand{\NaturalNumbers}{N}

% Integers
\DeclareNumberSetCommand{\Integers}{Z}

% Rational numbers
\DeclareNumberSetCommand{\RationalNumbers}{Q}

% Real Numbers
\DeclareNumberSetCommand{\RealNumbers}{R}

% Complex Numbers
\DeclareNumberSetCommand{\ComplexNumbers}{C}

\endinput