namespace Lagerbestand.Models;
///
/// Represents the storage area type for tire storage locations.
/// The value corresponds to position A in the location code (ABCD format).
///
public enum AreaType
{
///
/// Werkstatt (Gebäude 1, 3 Regalreihen) - Code prefix: 1
///
Werkstatt = 1,
///
/// Lager (Gebäude 2, 5 Regalreihen) - Code prefix: 2
///
Lager = 2
}
///
/// Extension methods for AreaType enum.
///
public static class AreaTypeExtensions
{
///
/// Gets the German display name for the area type.
///
public static string GetDisplayName(this AreaType areaType) => areaType switch
{
AreaType.Lager => "Lager",
AreaType.Werkstatt => "Werkstatt",
_ => areaType.ToString()
};
///
/// Gets the single-digit code for the area type.
///
public static string GetCode(this AreaType areaType) => ((int)areaType).ToString();
///
/// Gets the maximum shelf row number for the building.
/// Werkstatt (Gebäude 1) has 3 rows, Lager (Gebäude 2) has 5 rows.
///
public static int GetMaxRow(this AreaType areaType) => areaType switch
{
AreaType.Werkstatt => 3,
AreaType.Lager => 5,
_ => 1
};
///
/// Gets a display label including the building number (e.g., "Gebäude 1 – Werkstatt").
///
public static string GetBuildingLabel(this AreaType areaType) =>
$"Gebäude {(int)areaType} – {areaType.GetDisplayName()}";
///
/// Parses a code digit to AreaType.
///
/// Single digit code (1 or 2)
/// The corresponding AreaType
/// If code is not valid
public static AreaType FromCode(char code) => code switch
{
'1' => AreaType.Werkstatt,
'2' => AreaType.Lager,
_ => throw new ArgumentException($"Ungültiger Bereichscode: {code}. Erlaubt: 1 (Werkstatt), 2 (Lager)", nameof(code))
};
///
/// Tries to parse a code digit to AreaType.
///
public static bool TryFromCode(char code, out AreaType areaType)
{
areaType = default;
if (code == '1')
{
areaType = AreaType.Werkstatt;
return true;
}
if (code == '2')
{
areaType = AreaType.Lager;
return true;
}
return false;
}
}