using System;
namespace OpenNest.IO.Bom;
/// Whether a BOM row can be imported, and if not, why.
public enum BomRowStatus
{
/// Drawing found, material and thickness set: the row is imported.
Ready,
/// Drawing found but the material is blank.
NeedsMaterial,
/// Drawing found but the thickness is blank, zero or negative.
NeedsThickness,
/// No drawing file matches the row's file name.
NoDrawing,
/// The BOM row has no file name.
NoFileName,
}
///
/// One BOM line as the import dialog shows and edits it: the values read
/// from the BOM, the drawing file it resolved to and whether it can be
/// imported.
///
public class BomPartRow
{
public int? ItemNum { get; set; }
public string FileName { get; set; }
public int? Qty { get; set; }
public string Description { get; set; }
public string Material { get; set; }
public double? Thickness { get; set; }
/// The matched drawing file, or null when none was found.
public string DxfPath { get; set; }
public BomRowStatus Status
{
get
{
if (string.IsNullOrWhiteSpace(FileName))
return BomRowStatus.NoFileName;
if (string.IsNullOrWhiteSpace(DxfPath))
return BomRowStatus.NoDrawing;
if (string.IsNullOrWhiteSpace(Material))
return BomRowStatus.NeedsMaterial;
if (Thickness is not double thickness || !double.IsFinite(thickness) || thickness <= 0)
return BomRowStatus.NeedsThickness;
return BomRowStatus.Ready;
}
}
public string StatusText => Describe(Status);
///
/// True when the row has a drawing, so the operator can complete its
/// values; rows without one can never be imported.
///
public bool IsEditable => Status is not (BomRowStatus.NoFileName or BomRowStatus.NoDrawing);
public static string Describe(BomRowStatus status) =>
status switch
{
BomRowStatus.Ready => "Ready",
BomRowStatus.NeedsMaterial => "Needs material",
BomRowStatus.NeedsThickness => "Needs thickness",
BomRowStatus.NoDrawing => "No drawing found",
BomRowStatus.NoFileName => "No file name",
_ => throw new ArgumentOutOfRangeException(nameof(status), status, null),
};
}