%%%==============================================================================
%% Copyright 2022-23 by Alceu Frigeri
%%
%% This work may be distributed and/or modified under the conditions of
%%
%% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt),
%%   version 1.3c (or later), and/or
%% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html),
%%   version 3 (or later)
%%
%% This work has the LPPL maintenance status *maintained*.
%%
%% The Current Maintainer of this work is Alceu Frigeri
%%
%% This is version 1.11 (2023/05/29)
%%
%% The list of files that compose this work can be found in the README.md file at
%% https://ctan.org/pkg/ufrgscca
%%
%%%==============================================================================
%% UFRGS stands for "Federal University of Rio Grande do Sul" in south Brazil
%% EE    stands for "Engineering School"
%% CCA   stands for "Control and Automation Engineering Course" (Portuguese acronym)
%%%==============================================================================
\NeedsTeXFormat{LaTeX2e}[2022/06/01]
\def\tc@tmp@packname{ufrgscca-core}
\def\tc@tmp@altpackname{ufrgsccacore}
\def\tc@tmp@packdesc{UFRGS/CCA core commands}
\def\tc@tmp@packdate{2023/05/29}
\def\tc@tmp@packversion{1.11}
\let\@exp\expandafter
\@exp\edef\csname\tc@tmp@altpackname version\endcsname{\tc@tmp@packversion}
\@exp\@exp\@exp\ProvidesPackage\@exp\@exp\@exp{\@exp\tc@tmp@packname\@exp}\@exp[\tc@tmp@packdate\space v\tc@tmp@packversion\space\tc@tmp@packdesc]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
% student commands%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
\NewDocumentCommand{\tccore@articledefx}{mmmmm}{%
  \expandafter\gdef\csname #1article\endcsname{#2}%
  \expandafter\gdef\csname #1narticle\endcsname{#3}%
  \expandafter\gdef\csname #1Article\endcsname{#4}%
  \expandafter\gdef\csname #1Narticle\endcsname{#5}%
}%
\NewDocumentCommand{\tccore@articledefn}{m}{%
	\tccore@articledefx{#1}{o(a)}{(a)}{O(A)}{(A)}%
}%
\NewDocumentCommand{\tccore@articledefm}{m}{%
	\tccore@articledefx{#1}{o}{}{O}{}%
}%
\NewDocumentCommand{\tccore@articledeff}{m}{%
	\tccore@articledefx{#1}{a}{a}{A}{A}%
}%
\NewDocumentCommand{\tccore@articledef}{mm}{%
	\ifthenelse{\equal{#2}{m}}{%%
		\tccore@articledefm{#1}%%
	}{%%
 		\ifthenelse{\equal{#2}{f}}{%%
	 	  \tccore@articledeff{#1}%%
		}{%%
		  \tccore@articledefn{#1}%%
		}%%
	}%%
}%

%
% Exception:: those are only used at ufrgscca-forms, but, it make sense to be used at 'local.tex'
%
\cmdfactory<core>{formlocal}
\cmdfactory<core>{tccbrief,tcccoadvisorbrief,tccadvisorsreview}
\cmdfactory<core>{tccArgument}

\cmdfactory<core>{TCCcoordtitle}
\NewDocumentCommand{\TCCcoord}{mO{}}{%
	\tcgen@cdef<core>{TCCcoord}{#1}%
	\tccore@articledef{tcdef@core@TCCcoord}{#2}%%
}

\cmdfactory<core>{internshipcoordtitle}
\NewDocumentCommand{\internshipcoord}{mO{}}{%
    \tcgen@cdef<core>{internshipcoord}{#1}%
    \tccore@articledef{tcdef@core@internshipcoord}{#2}%%
}

\cmdfactory<core>{coursecoordtitle}%
\NewDocumentCommand{\coursecoord}{mO{}}{%
	\tcgen@cdef<core>{coursecoord}{#1}%
	\tccore@articledef{tcdef@core@coursecoord}{#2}%%
}
%
%
\def\tccore@ref@advisor{tc@student\Alph{tc@studentcount}@advisor}
\def\tccore@ref@coadvisor{tc@student\Alph{tc@studentcount}@coadvisor}
\def\tccore@ref@tutor{tc@student\Alph{tc@studentcount}@tutor}
\def\tccore@ref@supervisor{tc@student\Alph{tc@studentcount}@supervisor}
\def\tccore@ref@internship{tc@student\Alph{tc@studentcount}@internship}

\NewDocumentCommand{\tccore@examiners}{m}{\def\tc@@examiners{tc@student\Alph{tc@studentcount}@#1}}%
\def\tccore@ref@examiner{\tc@@examiners}
\def\tccore@ref@student{tc@student\Alph{tc@studentcount}}
\def\tccore@ref@coursecoord{tcdef@core@coursecoord}
\def\tccore@ref@TCCcoord{tcdef@core@TCCcoord}
\def\tccore@ref@internshipcoord{tcdef@core@internshipcoord}

\NewDocumentCommand{\tccore@@ref}{mm}{\expandafter\csname\csname tccore@ref@#1\endcsname#2\endcsname}%
%
%
\let\tc@org@author\author
%
\newcounter{tc@studentcount}%
\RenewDocumentCommand{\author}{mmO{}}{%
        \stepcounter{tc@studentcount}%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}last\endcsname{#1}%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}first\endcsname{#2}%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}\endcsname{#2 #1}%
		\tccore@articledef{tc@student\Alph{tc@studentcount}}{#3}%%
}%
%
\NewDocumentCommand{\authorinfo}{O{}mm}{%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}Nproc\endcsname{#1}%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}ID\endcsname{#2}%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}email\endcsname{#3}%
}%
\NewDocumentCommand{\student}{mmO{}}{\author{#1}{#2}[#3]}%
\NewDocumentCommand{\studentinfo}{O{}mm}{\authorinfo[#1]{#2}{#3}}%
%----------
%----------
%
\NewDocumentCommand{\tccore@ProfFields}{mmmmm}{%%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@#1last\endcsname{#3}%%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@#1first\endcsname{#4}%%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@#1\endcsname{#2~#4 #3}%%
		\tccore@articledef{tc@student\Alph{tc@studentcount}@#1}{#5}%

}%
\NewDocumentCommand{\tccore@ProfInfo}{mmmmm}{%%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@#1institution\endcsname{#2}%%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@#1titleinfo\endcsname{#3}%%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@#1email\endcsname{#4}%%
        \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@#1phone\endcsname{#5}%%
}%
%
%
%
\newcounter{tc@examinercount}[tc@studentcount]%
%
\NewDocumentCommand{\advisor}{O{}mmO{}}{%%
	\tccore@ProfFields{advisor}{#1}{#2}{#3}{#4}%%
%%% the advisor is also the first examiner if not @nBoard%
	\@ifundefined{tc@nBoard}{\examiner[#1]{#2}{#3}[#4]}{}%%
}%
\NewDocumentCommand{\advisorinfo}{mmmm}{%%
	\tccore@ProfInfo{advisor}{#1}{#2}{#3}{#4}%%
%%% the advisor is also the first examiner if not @nBoard%
	\@ifundefined{tc@nBoard}{\examinerinfo{#1}{#2}{#3}{#4}}{}%%
}%
%
\NewDocumentCommand{\coadvisor}{O{}mmO{}}{%%
				\tccore@ProfFields{coadvisor}{#1}{#2}{#3}{#4}%%
}%
\NewDocumentCommand{\coadvisorinfo}{mmmm}{%%
				\tccore@ProfInfo{coadvisor}{#1}{#2}{#3}{#4}%%
}%
%
%
\NewDocumentCommand{\tutor}{O{}mmO{}}{%%
    \tccore@ProfFields{tutor}{#1}{#2}{#3}{#4}%%
}%
\NewDocumentCommand{\tutorinfo}{mmmm}{%%
    \tccore@ProfInfo{tutor}{#1}{#2}{#3}{#4}%%
}%
%
%
\NewDocumentCommand{\supervisor}{O{}mmO{}}{%%
    \tccore@ProfFields{supervisor}{#1}{#2}{#3}{#4}%%
}%
\NewDocumentCommand{\supervisorinfo}{mmmm}{%%
  \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@supervisorregister\endcsname{#1}%%
  \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@supervisoroffice\endcsname{#2}%%
  \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@supervisoremail\endcsname{#3}%%
  \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@supervisorphone\endcsname{#4}%%
}%
\NewDocumentCommand{\internship}{mmmmm}{%%
  \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@internshipcompany\endcsname{#1}%%
  \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@internshipfield\endcsname{#2}%%
  \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@internshipstart\endcsname{#3}%%
  \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@internshipend\endcsname{#4}%%
  \expandafter\gdef\csname tc@student\Alph{tc@studentcount}@internshiplength\endcsname{#5}%%
}%
%
%
\NewDocumentCommand{\examiner}{O{}mmO{}}{%%
        \stepcounter{tc@examinercount}%%
				\tccore@ProfFields{examiner\Alph{tc@examinercount}}{#1}{#2}{#3}{#4}%%
}%
\NewDocumentCommand{\examinerinfo}{mmmm}{%%
				\tccore@ProfInfo{examiner\Alph{tc@examinercount}}{#1}{#2}{#3}{#4}%%
}%
%
\newcounter{tc@altexaminercount}[tc@studentcount]%
\NewDocumentCommand{\altexaminer}{O{}mmO{}}{%%
        \stepcounter{tc@altexaminercount}%%
				\tccore@ProfFields{altexaminer\Alph{tc@altexaminercount}}{#1}{#2}{#3}{#4}%%
}%
\NewDocumentCommand{\altexaminerinfo}{mmmm}{%%
				\tccore@ProfInfo{altexaminer\Alph{tc@altexaminercount}}{#1}{#2}{#3}{#4}%%
}%
%
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% assure that student/advisor/examiners... commands are defined with underlines (if not already defined)%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tc@IDrule{30mm}%
\def\tc@emailrule{40mm}%
\def\tc@namerule{50mm}%
\def\tc@titlerule{40mm}%
\def\tc@phonerule{20mm}%
\def\tc@agreerule{25mm}%
\def\tc@daterule{15mm}%
%%%
%%
%%%
\NewDocumentCommand{\tccore@emptyfields}{}{%

	\@ifundefined{tc@studentA}{%
		\student{\rule{\tc@namerule}{.1pt}}{}%
		\studentinfo{\rule{\tc@IDrule}{.1pt}}{\rule{\tc@emailrule}{.1pt}}%
	}{}%
	\@ifundefined{tc@studentA@advisor}{%
		\advisor{\rule{\tc@namerule}{.1pt}}{}%
		\advisorinfo{}{\rule{\tc@titlerule}{.1pt}}{\rule{\tc@emailrule}{.1pt}}{\rule{\tc@phonerule}{.1pt}}%
	}{}%
%
	\@ifundefined{tc@studentA@examinerC}{%
		\examiner{\rule{\tc@namerule}{.1pt}}{}%
		\examinerinfo{}{\rule{\tc@titlerule}{.1pt}}{\rule{\tc@emailrule}{.1pt}}{\rule{\tc@phonerule}{.1pt}}%
	}{}%
	\@ifundefined{tc@studentA@examinerC}{%
		\examiner{\rule{\tc@namerule}{.1pt}}{}%
		\examinerinfo{}{\rule{\tc@titlerule}{.1pt}}{\rule{\tc@emailrule}{.1pt}}{\rule{\tc@phonerule}{.1pt}}%
	}{}%
	\@ifundefined{tc@studentA@examinerC}{%
		\examiner{\rule{\tc@namerule}{.1pt}}{}%
		\examinerinfo{}{\rule{\tc@titlerule}{.1pt}}{\rule{\tc@emailrule}{.1pt}}{\rule{\tc@phonerule}{.1pt}}%
	}{}%
	\@ifundefined{tc@studentA@altexaminerA}{%
		\altexaminer{\rule{\tc@namerule}{.1pt}}{}%
		\altexaminerinfo{}{\rule{\tc@titlerule}{.1pt}}{\rule{\tc@emailrule}{.1pt}}{\rule{\tc@phonerule}{.1pt}}%
	}{}%
	%
	\@ifundefined{tc@studentA@supervisor}{%
        \supervisor{\rule{\tc@namerule}{.1pt}}{}%
        \supervisorinfo{\rule{\tc@phonerule}{.1pt}}{\rule{\tc@titlerule}{.1pt}}{\rule{\tc@emailrule}{.1pt}}{\rule{\tc@phonerule}{.1pt}}%
    }{}%
    %
    \@ifundefined{tc@studentA@tutor}{%
        \tutor{\rule{\tc@namerule}{.1pt}}{}%
        \tutorinfo{}{\rule{\tc@titlerule}{.1pt}}{\rule{\tc@emailrule}{.1pt}}{\rule{\tc@phonerule}{.1pt}}%
    }{}%
    %
    %
    \@ifundefined{tc@studentA@internshipcompany}{%
        \internship{\rule{\tc@namerule}{.1pt}}{\rule{\tc@titlerule}{.1pt}}{\rule{\tc@daterule}{.1pt}}{\rule{\tc@daterule}{.1pt}}{\rule{\tc@daterule}{.1pt}}%
    }{}%

    %
	% add an \iftcif@forms !!!
	%
	\@ifundefined{tcdef@core@tccbrief}{%
		\tccbrief{\tcdef@core@formsblanklines}%
	}{}%
	\@ifundefined{tcdef@core@tccArgument}{%
		\tccArgument{\tcdef@core@formsblanklines}%
	}{}%
	\@ifundefined{tcdef@core@tcccoadvisorbrief}{%
		\tcccoadvisorbrief{\tcdef@core@formsblanklines}%
	}{}%
	\@ifundefined{tcdef@core@tccadvisorsreview}{%
		\tccadvisorsreview{\tcdef@core@formsblanklines}%
	}{}%
}%

\NewDocumentCommand{\tccore@resetfields}{}{%
	\setcounter{tc@studentcount}{0}
	\csundef{tc@studentA}
	\csundef{tc@studentA@advisor}
	\csundef{tc@studentA@coadvisor}
	\csundef{tc@studentA@examinerC}
	\csundef{tc@studentA@altexaminerA}
    \csundef{tc@studentA@supervisor}
    \csundef{tc@studentA@tutor}
    \csundef{tc@studentA@internshipcompany}
%    \csundef{tc@studentA@internshipfield}
%    \csundef{tc@studentA@internshipstart}
%    \csundef{tc@studentA@internshipend}
%    \csundef{tc@studentA@internshiplength}
	\csundef{tcdef@core@tccbrief}
	\csundef{tcdef@core@tccArgument}
	\csundef{tcdef@core@tcccoadvisorbrief}
	\csundef{tcdef@core@tccadvisorsreview}
}
