\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{uniflow}

\RequirePackage{comment}
  \includecomment{problem}

\newif\ifuniFirstOrder\uniFirstOrdertrue

\DeclareOption{batch}{%
\ifx\conditionmacro\undefined
  \immediate\write18{
    pdflatex
    "\gdef\string\conditionmacro{corrector} \string\input\space\jobname"
  }
  \immediate\write18{
    pdflatex --jobname=\jobname-student
    "\gdef\string\conditionmacro{student} \string\input\space\jobname"
  }
  \immediate\write18{
    pdflatex --jobname=\jobname-teacher
    "\gdef\string\conditionmacro{teacher} \string\input\space\jobname"
  }
  \expandafter\stop
\fi
}

\DeclareOption{student}{%
  \ifuniFirstOrder
    \excludecomment{solution}
    \excludecomment{howtograde}
  \fi
}
\DeclareOption{teacher}{%
  \ifuniFirstOrder
    \includecomment{solution}
    \excludecomment{howtograde}
  \fi
}
\DeclareOption{corrector}{%
  \ifuniFirstOrder
    \includecomment{solution}
    \includecomment{howtograde}
  \fi
}
\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article}
}

\ifx\conditionmacro\undefined
  \ExecuteOptions{corrector} % set default view
\else
  \ExecuteOptions{\conditionmacro}
  \uniFirstOrderfalse
\fi
\ProcessOptions\relax

\LoadClass{article}