using System.ComponentModel.DataAnnotations;

namespace GerbilManagerWebAPI.Models
{
    /// <summary>A litter (Wurf). Parents are gerbils; juveniles are Gerbils linked via Gerbil.LitterId.</summary>
    public class Litter
    {
        [Key]
        public Guid Id { get; set; }
        public required string Name { get; set; }
        public DateOnly? Date { get; set; }

        /// <summary>Total born count (was "Strength").</summary>
        public int? TotalBorn { get; set; }

        /// <summary>Frühsterblichkeit: Anzahl der in den ersten 8 Wochen verstorbenen Tiere.
        /// Null = unbekannt (Altdaten). Must be ≤ TotalBorn if both are set.</summary>
        public int? DeathsWithin8Weeks { get; set; }

        /// <summary>Totgeburten (TG): tot geborene Jungtiere dieses Wurfs. Getrennt von
        /// DeathsWithin8Weeks (in den ersten 8 Wochen verstorben). Aus der xlsx-Wurfchronik
        /// (litters.json breakdown) importiert. Null = unbekannt/nicht erfasst.</summary>
        public int? Stillborn { get; set; }

        public Guid? FatherId { get; set; }
        public Gerbil? Father { get; set; }
        public Guid? MotherId { get; set; }
        public Gerbil? Mother { get; set; }

        /// <summary>Computed ~35 days after Date by default; editable.</summary>
        public DateOnly? ExpectedGoHomeDate { get; set; }
        public string? Notes { get; set; }

        /// <summary>Zuchtnummer der Verpaarung (Wurfchronik col H) — pairing-level code;
        /// litters sharing it are the same Zuchtpaar. Set by the FEAT-8 import.</summary>
        public string? PairingCode { get; set; }

        /// <summary>DB-5: stable import source id (extract.py litter Id). Unique (filtered,
        /// nulls allowed for manually-entered litters). Primary idempotency key for re-imports;
        /// Name+Date is the fallback for litters created before this column existed.</summary>
        public string? ExternalRef { get; set; }

        /// <summary>FEAT-NAMEGEN: Wurfbuchstabe (A, B, C … AA, AB …) — alle Welpen dieses
        /// Wurfs erhalten Namen mit diesem Anfangsbuchstaben (gängige Zuchtkonvention).</summary>
        public string? LitterLetter { get; set; }

        /// <summary>Data-provenance / traceability for the import: a JSON object describing
        /// WHICH source information produced this litter (sourceFiles, mergedRecordCount,
        /// fromWurfchronik, notes — e.g. "aus Wurfchronik", "aus Stammbaum-Diagramm rekonstruiert").
        /// Written by the Python merge_and_resolve step and surfaced read-only ("Datenherkunft").
        /// Null = manually-added litter / no import data.</summary>
        public string? Provenance { get; set; }

        /// <summary>Steuert, ob dieser Wurf in der Wurfchronik (Würfe-Liste) erscheint.
        /// true = normal sichtbar. false = aus der Wurfchronik ausgeblendet, aber weiterhin
        /// auf der Tier-Detailseite des Eltern­tiers sichtbar — z. B. ein extern (bei einer
        /// anderen Zucht) entstandener Wurf eines nicht-residenten Tieres, der nur zur
        /// Dokumentation der Abstammung gehört. Default true (alle bestehenden Würfe).</summary>
        public bool ShowInChronicle { get; set; } = true;

        /// <summary>true = manually created in the UI; false = produced by an import path. The ingest
        /// re-import wipe deletes ONLY IsManual=false litters, so a manually-added litter (e.g. the
        /// birth litter of a manual animal) is never wiped. All import paths leave this false.</summary>
        public bool IsManual { get; set; }
    }
}
