namespace PowderCoating.Core.Entities;

/// <summary>
/// Platform-level master list of powder coating products across all vendors.
/// Not tenant-scoped — no BaseEntity, no CompanyId, no soft delete.
/// Used as a lookup table to auto-fill inventory records without an API call.
/// </summary>
public class PowderCatalogItem
{
    public int Id { get; set; }

    /// <summary>Vendor name — e.g. "Prismatic Powders", "Columbia Coatings". Unique index with Sku.</summary>
    public string VendorName { get; set; } = string.Empty;

    /// <summary>Vendor's product SKU. Unique per vendor.</summary>
    public string Sku { get; set; } = string.Empty;

    public string ColorName { get; set; } = string.Empty;

    /// <summary>Cleaned short description — boilerplate stripped at import time.</summary>
    public string? Description { get; set; }

    /// <summary>Base unit price (lowest quantity tier).</summary>
    public decimal UnitPrice { get; set; }

    /// <summary>Full price tier JSON for future quantity-break pricing support.</summary>
    public string? PriceTiersJson { get; set; }

    public string? ImageUrl { get; set; }
    public string? SdsUrl { get; set; }
    public string? TdsUrl { get; set; }
    public string? ApplicationGuideUrl { get; set; }
    public string? ProductUrl { get; set; }

    // ── Coating specification fields ──────────────────────────────────────

    /// <summary>Cure temperature in degrees Fahrenheit.</summary>
    public decimal? CureTemperatureF { get; set; }

    /// <summary>Cure hold time at cure temperature, in minutes.</summary>
    public int? CureTimeMinutes { get; set; }

    /// <summary>
    /// Raw cure schedule text exactly as supplied by the vendor — e.g. "10 minutes @ 400°F".
    /// Preserved verbatim because vendor formats vary wildly and some carry application notes
    /// that don't reduce to a single temp/time pair (partial cures, clear-coat steps).
    /// </summary>
    public string? CureScheduleText { get; set; }

    /// <summary>
    /// All parsed cure curves as JSON — e.g. [{"tempF":400,"minutes":10},{"tempF":350,"minutes":20}].
    /// Many powders list alternate lower-temperature curves; these matter for heat-sensitive
    /// substrates that cannot take the standard 400°F cure, so we keep every curve, not just the
    /// primary one in <see cref="CureTemperatureF"/>/<see cref="CureTimeMinutes"/>.
    /// </summary>
    public string? CureCurvesJson { get; set; }

    /// <summary>Finish type — e.g. Gloss, Matte, Satin, Metallic, Texture.</summary>
    public string? Finish { get; set; }

    /// <summary>Resin chemistry — e.g. "Polyester", "TGIC", "Epoxy", "Hybrid". Distinct from <see cref="Finish"/>.</summary>
    public string? ChemistryType { get; set; }

    /// <summary>Recommended film build (mil thickness) as free text from the vendor — e.g. "2.0-3.0 Mils".</summary>
    public string? MilThickness { get; set; }

    /// <summary>Comma-separated color family tags — e.g. "Blue,Purple".</summary>
    public string? ColorFamilies { get; set; }

    /// <summary>Whether this product requires a clear coat to activate its effect.</summary>
    public bool? RequiresClearCoat { get; set; }

    /// <summary>Theoretical coverage in sq ft per pound. Typical 80–120.</summary>
    public decimal? CoverageSqFtPerLb { get; set; }

    /// <summary>Specific gravity from the TDS. Used to derive theoretical coverage when needed.</summary>
    public decimal? SpecificGravity { get; set; }

    /// <summary>Powder transfer efficiency percentage. Typical 60–75%.</summary>
    public decimal? TransferEfficiency { get; set; }

    // ── Catalog management ────────────────────────────────────────────────

    /// <summary>
    /// Our internal product category — e.g. "Powder Additives" for pigments/additives that are
    /// sold by weight in grams and mixed into clear rather than sprayed as a standalone powder.
    /// Null/empty for standard powders. Derived at import from the vendor's taxonomy, NOT stored
    /// from their raw category list.
    /// </summary>
    public string? Category { get; set; }

    /// <summary>
    /// Provenance of this record — e.g. "Columbia Coatings API". Kept SEPARATE from
    /// <see cref="VendorName"/> (which holds the derived manufacturer) so we can honor a
    /// distributor's right-to-delete by purging every record that came from their feed,
    /// regardless of which manufacturer made the product.
    /// </summary>
    public string? Source { get; set; }

    /// <summary>
    /// Reformulation history as supplied by the vendor — e.g. "Formulation Change: 05/22/26".
    /// Not a reliable modified-date (free text, reformulations only) but a useful signal that a
    /// product's formula — and therefore its cure specs — may have changed.
    /// </summary>
    public string? FormulationChanges { get; set; }

    /// <summary>True when the vendor has discontinued this product. Kept for historical lookups.</summary>
    public bool IsDiscontinued { get; set; } = false;

    /// <summary>True when this record was contributed by a tenant label scan rather than a curated import.</summary>
    public bool IsUserContributed { get; set; } = false;

    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    public DateTime? UpdatedAt { get; set; }

    /// <summary>Timestamp of the last successful sync run for this record.</summary>
    public DateTime? LastSyncedAt { get; set; }
}
