Files
Extrudex/backend/Domain/Entities/FilamentUsage.cs
rex-bot 311dd2ee7f
Some checks failed
Dev Build / build-test (pull_request) Failing after 58s
Dev Build / deploy-dev (pull_request) Has been skipped
Dev Build / notify-success (pull_request) Has been skipped
Dev Build / notify-failure (pull_request) Successful in 4s
feat(CUB-31): [Extrudex] Add filament usage tracking model
2026-04-26 18:35:37 +00:00

73 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Extrudex.Domain.Base;
namespace Extrudex.Domain.Entities;
/// <summary>
/// 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).
/// </summary>
public class FilamentUsage : AuditableEntity
{
/// <summary>
/// Foreign key to the print job that consumed this filament.
/// A usage record is always tied to a print job.
/// </summary>
public Guid PrintJobId { get; set; }
/// <summary>
/// Navigation to the print job that consumed this filament.
/// </summary>
public PrintJob PrintJob { get; set; } = null!;
/// <summary>
/// Foreign key to the spool (filament) that provided the material.
/// Links usage back to the specific physical spool for inventory tracking.
/// </summary>
public Guid SpoolId { get; set; }
/// <summary>
/// Navigation to the spool that provided the material.
/// </summary>
public Spool Spool { get; set; } = null!;
/// <summary>
/// Foreign key to the printer that executed the print job.
/// Denormalized from PrintJob for direct querying of per-printer usage.
/// </summary>
public Guid PrinterId { get; set; }
/// <summary>
/// Navigation to the printer that executed the print job.
/// </summary>
public Printer Printer { get; set; } = null!;
/// <summary>
/// Grams of filament consumed during this print job.
/// Derived from mm_extruded × cross_section_area × material_density,
/// or measured directly from AMS weight delta.
/// </summary>
public decimal GramsUsed { get; set; }
/// <summary>
/// Millimeters of filament extruded for this usage record.
/// The primary physical measurement; grams_used is derived from this.
/// </summary>
public decimal MmExtruded { get; set; }
/// <summary>
/// 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.
/// </summary>
public DateTime RecordedAt { get; set; } = DateTime.UtcNow;
/// <summary>
/// Optional notes about this usage record (e.g., "AMS tray 3", "manual weight check").
/// </summary>
public string? Notes { get; set; }
}