using Core.Models;
namespace GoogleSheetsScheduleImport;
///
/// Strips leading MS / HS markers from grid titles so titles can be fuzzy-matched to .
///
public static class SchoolLevelPrefixParser
{
/// Remainder text and school level when unambiguous; null level for MS/HS combined or unknown.
public static (string Remainder, SchoolLevel? Level) StripLeadingSchoolPrefix(string raw)
{
var s = TextNormalization.ForEmitLine(raw);
if (string.IsNullOrEmpty(s))
return (s, null);
if (s.StartsWith("MS/HS", StringComparison.OrdinalIgnoreCase))
{
var rest = s[5..].TrimStart();
if (rest.StartsWith('/'))
rest = rest[1..].TrimStart();
return (rest, null);
}
if (s.Length >= 3 && s.StartsWith("MS ", StringComparison.OrdinalIgnoreCase))
return (s[3..].TrimStart(), SchoolLevel.MiddleSchool);
if (s.Length >= 3 && s.StartsWith("HS ", StringComparison.OrdinalIgnoreCase))
return (s[3..].TrimStart(), SchoolLevel.HighSchool);
if (s.Length >= 3 && s.StartsWith("MS/", StringComparison.OrdinalIgnoreCase))
return (s[3..].TrimStart(), SchoolLevel.MiddleSchool);
if (s.Length >= 3 && s.StartsWith("HS/", StringComparison.OrdinalIgnoreCase))
return (s[3..].TrimStart(), SchoolLevel.HighSchool);
return (s, null);
}
public static string ToSectionSuffix(SchoolLevel level) =>
level == SchoolLevel.MiddleSchool ? "MS" : "HS";
}