namespace JobTrackerApi.Models;

// The Career Workspace's durable source of truth. Bounded to one row per user for now
// (see career-workspace-implementation-roadmap.md Phase F1) -- ProfileJson mirrors
// ApplicationUser.ProfileCvStructureJson during the dual-write window and will become
// authoritative once every read path is migrated (F5).
public sealed class CareerProfile
{
    public int Id { get; set; }
    public string OwnerUserId { get; set; } = string.Empty;

    // Phase 3: ProfileJson is now a DERIVED projection of the relational children + LongTailJson,
    // serialized into the StructuredCvProfile shape and kept in sync on every save so the legacy
    // read paths (CV rendering, tailoring, match-score) keep working unchanged. It is no longer an
    // independently editable source. See docs/architecture/career-profile-model.md §4.
    public string ProfileJson { get; set; } = string.Empty;

    // The editable long tail that is not worth a relational table: contact, summary, interests,
    // achievements, organisations, publications, courses, custom/other sections, and AI-extraction
    // metadata. A JSON object (CareerLongTail). The relational children (Experience/Education/Skill/
    // Project/Certification/Language) hold the rest.
    public string LongTailJson { get; set; } = string.Empty;

    public int Version { get; set; }
    public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;

    public List<CareerExperience> Experiences { get; set; } = new();
    public List<CareerEducation> Education { get; set; } = new();
    public List<CareerSkill> Skills { get; set; } = new();
    public List<CareerProject> Projects { get; set; } = new();
    public List<CareerCertification> Certifications { get; set; } = new();
    public List<CareerLanguage> Languages { get; set; } = new();
}

// Append-only history: one row per save, so profile edits are never silently lost.
public sealed class CareerProfileVersion
{
    public int Id { get; set; }
    public string OwnerUserId { get; set; } = string.Empty;
    public int CareerProfileId { get; set; }
    public CareerProfile? CareerProfile { get; set; }
    public int Version { get; set; }
    public string ProfileJson { get; set; } = string.Empty;
    // Where this version came from: "upload" | "rebuild" | "improve" | "reprocess" | "parse" | "manual".
    public string Source { get; set; } = string.Empty;
    public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}
