namespace Lagerbestand.Models;
///
/// Represents the position within a shelf slot (side + level).
/// The value corresponds to position C in the location code (ABCD format).
///
public enum ShelfPosition
{
///
/// Links oben - Code: 1
///
LinksOben = 1,
///
/// Links unten - Code: 2
///
LinksUnten = 2,
///
/// Rechts oben - Code: 3
///
RechtsOben = 3,
///
/// Rechts unten - Code: 4
///
RechtsUnten = 4
}
///
/// Extension methods for ShelfPosition enum.
///
public static class ShelfPositionExtensions
{
///
/// Gets the German display name for the shelf position.
///
public static string GetDisplayName(this ShelfPosition position) => position switch
{
ShelfPosition.LinksOben => "Links oben",
ShelfPosition.LinksUnten => "Links unten",
ShelfPosition.RechtsOben => "Rechts oben",
ShelfPosition.RechtsUnten => "Rechts unten",
_ => position.ToString()
};
///
/// Gets a short display name (e.g., "L↑") for compact grid views.
///
public static string GetShortName(this ShelfPosition position) => position switch
{
ShelfPosition.LinksOben => "L↑",
ShelfPosition.LinksUnten => "L↓",
ShelfPosition.RechtsOben => "R↑",
ShelfPosition.RechtsUnten => "R↓",
_ => position.ToString()
};
///
/// Whether the position is on the left side of the shelf.
///
public static bool IsLeft(this ShelfPosition position) =>
position is ShelfPosition.LinksOben or ShelfPosition.LinksUnten;
///
/// Whether the position is on the top level of the shelf.
///
public static bool IsTop(this ShelfPosition position) =>
position is ShelfPosition.LinksOben or ShelfPosition.RechtsOben;
///
/// Gets the single-digit code for the position.
///
public static string GetCode(this ShelfPosition position) => ((int)position).ToString();
///
/// Parses a code digit to ShelfPosition.
///
/// Single digit code (1-4)
/// If code is not valid
public static ShelfPosition FromCode(char code) => code switch
{
'1' => ShelfPosition.LinksOben,
'2' => ShelfPosition.LinksUnten,
'3' => ShelfPosition.RechtsOben,
'4' => ShelfPosition.RechtsUnten,
_ => throw new ArgumentException($"Ungültiger Positionscode: {code}. Erlaubt: 1-4", nameof(code))
};
///
/// Tries to parse a code digit to ShelfPosition.
///
public static bool TryFromCode(char code, out ShelfPosition position)
{
position = default;
if (code is < '1' or > '4')
return false;
position = (ShelfPosition)(code - '0');
return true;
}
///
/// All shelf positions in display order.
///
public static readonly ShelfPosition[] All =
[
ShelfPosition.LinksOben,
ShelfPosition.LinksUnten,
ShelfPosition.RechtsOben,
ShelfPosition.RechtsUnten
];
}