<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2014-2023 Ryan Specialty, LLC.

  This file is part of tame-core.

  tame-core is free software: you can redistribute it and/or modify it
  under the terms of the GNU General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
<package xmlns="http://www.lovullo.com/rater"
         xmlns:c="http://www.lovullo.com/calc"
         xmlns:t="http://www.lovullo.com/rater/apply-template"
         core="true"
         desc="United States">

  <import package="base" />
  <import package="vector/stub" />


  <section title="States">
    The type \ref{State} contains each of the States in the United~States,
      with the addition of Washington~DC.
    The States are 1-indexed and sorted by \emph{abbreviation}\footnote{
      States are sorted by abbreviation rather than the State name beacuse
        they are most frequently referenced as such.}.

    <typedef name="State" desc="States">
      <enum type="integer">
        <item name="STATE_NONE" value="0"  desc="No State"       />
        <item name="STATE_AK"   value="1"  desc="Alaska"         />
        <item name="STATE_AL"   value="2"  desc="Alabama"        />
        <item name="STATE_AR"   value="3"  desc="Arkansas"       />
        <item name="STATE_AZ"   value="4"  desc="Arizona"        />
        <item name="STATE_CA"   value="5"  desc="California"     />
        <item name="STATE_CO"   value="6"  desc="Colorado"       />
        <item name="STATE_CT"   value="7"  desc="Connecticut"    />
        <item name="STATE_DC"   value="8"  desc="Washington DC"  />
        <item name="STATE_DE"   value="9"  desc="Delaware"       />
        <item name="STATE_FL"   value="10" desc="Florida"        />
        <item name="STATE_GA"   value="11" desc="Georgia"        />
        <item name="STATE_HI"   value="12" desc="Hawaii"         />
        <item name="STATE_IA"   value="13" desc="Iowa"           />
        <item name="STATE_ID"   value="14" desc="Idaho"          />
        <item name="STATE_IL"   value="15" desc="Illinois"       />
        <item name="STATE_IN"   value="16" desc="Indiana"        />
        <item name="STATE_KS"   value="17" desc="Kansas"         />
        <item name="STATE_KY"   value="18" desc="Kentucky"       />
        <item name="STATE_LA"   value="19" desc="Louisiana"      />
        <item name="STATE_MA"   value="20" desc="Massachusetts"  />
        <item name="STATE_MD"   value="21" desc="Maryland"       />
        <item name="STATE_ME"   value="22" desc="Maine"          />
        <item name="STATE_MI"   value="23" desc="Michigan"       />
        <item name="STATE_MN"   value="24" desc="Minnesota"      />
        <item name="STATE_MO"   value="25" desc="Missouri"       />
        <item name="STATE_MS"   value="26" desc="Mississippi"    />
        <item name="STATE_MT"   value="27" desc="Montana"        />
        <item name="STATE_NC"   value="28" desc="North Carolina" />
        <item name="STATE_ND"   value="29" desc="North Dakota"   />
        <item name="STATE_NE"   value="30" desc="Nebraska"       />
        <item name="STATE_NH"   value="31" desc="New Hampshire"  />
        <item name="STATE_NJ"   value="32" desc="New Jersey"     />
        <item name="STATE_NM"   value="33" desc="New Mexico"     />
        <item name="STATE_NV"   value="34" desc="Nevada"         />
        <item name="STATE_NY"   value="35" desc="New York"       />
        <item name="STATE_OH"   value="36" desc="Ohio"           />
        <item name="STATE_OK"   value="37" desc="Oklahoma"       />
        <item name="STATE_OR"   value="38" desc="Oregon"         />
        <item name="STATE_PA"   value="39" desc="Pennsylvania"   />
        <item name="STATE_RI"   value="40" desc="Rhode Island"   />
        <item name="STATE_SC"   value="41" desc="South Carolina" />
        <item name="STATE_SD"   value="42" desc="South Dakota"   />
        <item name="STATE_TN"   value="43" desc="Tennessee"      />
        <item name="STATE_TX"   value="44" desc="Texas"          />
        <item name="STATE_UT"   value="45" desc="Utah"           />
        <item name="STATE_VA"   value="46" desc="Virginia"       />
        <item name="STATE_VT"   value="47" desc="Vermont"        />
        <item name="STATE_WA"   value="48" desc="Washington"     />
        <item name="STATE_WI"   value="49" desc="Wisconsin"      />
        <item name="STATE_WV"   value="50" desc="West Virginia"  />
        <item name="STATE_WY"   value="51" desc="Wyoming"        />
      </enum>
    </typedef>
  </section>



  <section title="State Operations">
    For operations that involve taking values of all states where order
      matters (e.g. for index alignment),
        querying the symbol table isn't appropriate,
          as it does not guarantee order.
    \ref{_for-each-state_} can be used for that purpose;
      it exposes the following template values to its body:

    \begin{enumerate}
      \item \tt{@state_const@} contains the State constant;
      \item \tt{@state_upper@} contains the uppercase two-letter State
              abbreviation;
      \item \tt{@state_lower@} contains the lowercase two-letter State
              abbreviation; and
      \item \tt{@state_name@} contains the full state name.
    \end{enumerate}

    This can be used to generate a ^[State vector] by mapping an iteration
      index to the State constant~\tt{@state_const@}.
    Note that \ref{STATE_NONE} is not in the list.

    <template name="_for-each-state_"
              desc="Apply body for each State">
      <param name="@values@" desc="Body to apply per State" />


      <inline-template>
        <for-each>
          <set state_const="STATE_AK" state_upper="AK" state_lower="ak" upper_lower="Ak" state_name="Alaska"         />
          <set state_const="STATE_AL" state_upper="AL" state_lower="al" upper_lower="Al" state_name="Alabama"        />
          <set state_const="STATE_AR" state_upper="AR" state_lower="ar" upper_lower="Ar" state_name="Arkansas"       />
          <set state_const="STATE_AZ" state_upper="AZ" state_lower="az" upper_lower="Az" state_name="Arizona"        />
          <set state_const="STATE_CA" state_upper="CA" state_lower="ca" upper_lower="Ca" state_name="California"     />
          <set state_const="STATE_CO" state_upper="CO" state_lower="co" upper_lower="Co" state_name="Colorado"       />
          <set state_const="STATE_CT" state_upper="CT" state_lower="ct" upper_lower="Ct" state_name="Connecticut"    />
          <set state_const="STATE_DC" state_upper="DC" state_lower="dc" upper_lower="Dc" state_name="Washington DC"  />
          <set state_const="STATE_DE" state_upper="DE" state_lower="de" upper_lower="De" state_name="Delaware"       />
          <set state_const="STATE_FL" state_upper="FL" state_lower="fl" upper_lower="Fl" state_name="Florida"        />
          <set state_const="STATE_GA" state_upper="GA" state_lower="ga" upper_lower="Ga" state_name="Georgia"        />
          <set state_const="STATE_HI" state_upper="HI" state_lower="hi" upper_lower="Hi" state_name="Hawaii"         />
          <set state_const="STATE_IA" state_upper="IA" state_lower="ia" upper_lower="Ia" state_name="Iowa"           />
          <set state_const="STATE_ID" state_upper="ID" state_lower="id" upper_lower="Id" state_name="Idaho"          />
          <set state_const="STATE_IL" state_upper="IL" state_lower="il" upper_lower="Il" state_name="Illinois"       />
          <set state_const="STATE_IN" state_upper="IN" state_lower="in" upper_lower="In" state_name="Indiana"        />
          <set state_const="STATE_KS" state_upper="KS" state_lower="ks" upper_lower="Ks" state_name="Kansas"         />
          <set state_const="STATE_KY" state_upper="KY" state_lower="ky" upper_lower="Ky" state_name="Kentucky"       />
          <set state_const="STATE_LA" state_upper="LA" state_lower="la" upper_lower="La" state_name="Louisiana"      />
          <set state_const="STATE_MA" state_upper="MA" state_lower="ma" upper_lower="Ma" state_name="Massachusetts"  />
          <set state_const="STATE_MD" state_upper="MD" state_lower="md" upper_lower="Md" state_name="Maryland"       />
          <set state_const="STATE_ME" state_upper="ME" state_lower="me" upper_lower="Me" state_name="Maine"          />
          <set state_const="STATE_MI" state_upper="MI" state_lower="mi" upper_lower="Mi" state_name="Michigan"       />
          <set state_const="STATE_MN" state_upper="MN" state_lower="mn" upper_lower="Mn" state_name="Minnesota"      />
          <set state_const="STATE_MO" state_upper="MO" state_lower="mo" upper_lower="Mo" state_name="Missouri"       />
          <set state_const="STATE_MS" state_upper="MS" state_lower="ms" upper_lower="Ms" state_name="Mississippi"    />
          <set state_const="STATE_MT" state_upper="MT" state_lower="mt" upper_lower="Mt" state_name="Montana"        />
          <set state_const="STATE_NC" state_upper="NC" state_lower="nc" upper_lower="Nc" state_name="North Carolina" />
          <set state_const="STATE_ND" state_upper="ND" state_lower="nd" upper_lower="Nd" state_name="North Dakota"   />
          <set state_const="STATE_NE" state_upper="NE" state_lower="ne" upper_lower="Ne" state_name="Nebraska"       />
          <set state_const="STATE_NH" state_upper="NH" state_lower="nh" upper_lower="Nh" state_name="New Hampshire"  />
          <set state_const="STATE_NJ" state_upper="NJ" state_lower="nj" upper_lower="Nj" state_name="New Jersey"     />
          <set state_const="STATE_NM" state_upper="NM" state_lower="nm" upper_lower="Nm" state_name="New Mexico"     />
          <set state_const="STATE_NV" state_upper="NV" state_lower="nv" upper_lower="Nv" state_name="Nevada"         />
          <set state_const="STATE_NY" state_upper="NY" state_lower="ny" upper_lower="Ny" state_name="New York"       />
          <set state_const="STATE_OH" state_upper="OH" state_lower="oh" upper_lower="Oh" state_name="Ohio"           />
          <set state_const="STATE_OK" state_upper="OK" state_lower="ok" upper_lower="Ok" state_name="Oklahoma"       />
          <set state_const="STATE_OR" state_upper="OR" state_lower="or" upper_lower="Or" state_name="Oregon"         />
          <set state_const="STATE_PA" state_upper="PA" state_lower="pa" upper_lower="Pa" state_name="Pennsylvania"   />
          <set state_const="STATE_RI" state_upper="RI" state_lower="ri" upper_lower="Ri" state_name="Rhode Island"   />
          <set state_const="STATE_SC" state_upper="SC" state_lower="sc" upper_lower="Sc" state_name="South Carolina" />
          <set state_const="STATE_SD" state_upper="SD" state_lower="sd" upper_lower="Sd" state_name="South Dakota"   />
          <set state_const="STATE_TN" state_upper="TN" state_lower="tn" upper_lower="Tn" state_name="Tennessee"      />
          <set state_const="STATE_TX" state_upper="TX" state_lower="tx" upper_lower="Tx" state_name="Texas"          />
          <set state_const="STATE_UT" state_upper="UT" state_lower="ut" upper_lower="Ut" state_name="Utah"           />
          <set state_const="STATE_VA" state_upper="VA" state_lower="va" upper_lower="Va" state_name="Virginia"       />
          <set state_const="STATE_VT" state_upper="VT" state_lower="vt" upper_lower="Vt" state_name="Vermont"        />
          <set state_const="STATE_WA" state_upper="WA" state_lower="wa" upper_lower="Wa" state_name="Washington"     />
          <set state_const="STATE_WI" state_upper="WI" state_lower="wi" upper_lower="Wi" state_name="Wisconsin"      />
          <set state_const="STATE_WV" state_upper="WV" state_lower="wv" upper_lower="Wv" state_name="West Virginia"  />
          <set state_const="STATE_WY" state_upper="WY" state_lower="wy" upper_lower="Wy" state_name="Wyoming"        />
        </for-each>

        <param-copy name="@values@" />
      </inline-template>
    </template>


    To ease iteration though ^[State vector]s generated with
      \ref{_for-each-state_},
        a 52~vector \ref{NVEC_STATE_ALL} and classification \ref{state-all}
        are provided.

    <t:n-vector n="52" name="NVEC_STATE_ALL" value="1" />

    <classify as="state-all" yields="stateAll"
              desc="Every State in a State vector">
      <match on="NVEC_STATE_ALL" />
    </classify>
  </section>
</package>
