using Extrudex.Domain.Base;
namespace Extrudex.Domain.Entities;
///
/// Tracks filament consumption for a specific print job on a specific spool.
/// Each record captures the grams used, which printer consumed it, and when the
/// usage was recorded. This enables granular per-job usage analytics, COGS
/// reconciliation, and spool weight depletion tracking.
///
/// A single PrintJob may have multiple FilamentUsage records if multiple spools
/// were consumed (e.g., multi-material prints via AMS).
///
public class FilamentUsage : AuditableEntity
{
///
/// Foreign key to the print job that consumed this filament.
/// A usage record is always tied to a print job.
///
public Guid PrintJobId { get; set; }
///
/// Navigation to the print job that consumed this filament.
///
public PrintJob PrintJob { get; set; } = null!;
///
/// Foreign key to the spool (filament) that provided the material.
/// Links usage back to the specific physical spool for inventory tracking.
///
public Guid SpoolId { get; set; }
///
/// Navigation to the spool that provided the material.
///
public Spool Spool { get; set; } = null!;
///
/// Foreign key to the printer that executed the print job.
/// Denormalized from PrintJob for direct querying of per-printer usage.
///
public Guid PrinterId { get; set; }
///
/// Navigation to the printer that executed the print job.
///
public Printer Printer { get; set; } = null!;
///
/// Grams of filament consumed during this print job.
/// Derived from mm_extruded × cross_section_area × material_density,
/// or measured directly from AMS weight delta.
///
public decimal GramsUsed { get; set; }
///
/// Millimeters of filament extruded for this usage record.
/// The primary physical measurement; grams_used is derived from this.
///
public decimal MmExtruded { get; set; }
///
/// Timestamp when this usage record was created (UTC).
/// Represents when the usage was first logged, which may differ from
/// the print job's started_at or completed_at timestamps.
///
public DateTime RecordedAt { get; set; } = DateTime.UtcNow;
///
/// Optional notes about this usage record (e.g., "AMS tray 3", "manual weight check").
///
public string? Notes { get; set; }
}