namespace JobTrackerApi.Models;

// Phase 4 — Career Workspace Builder.
//
// A CvVariant is NOT another career profile. It is a *lens* over the master CareerProfile: which
// sections show, in what order, with what per-item overrides, rendered through a chosen theme with
// layout/colour/font settings. The career data is never duplicated here — the variant stores only
// selections + overrides keyed by the master profile's stable ItemKeys, plus builder preferences.
// docs/architecture/cv-builder.md.
public sealed class CvVariant
{
    public int Id { get; set; }
    public string OwnerUserId { get; set; } = string.Empty;

    // Public share slug for /cv/{slug}. Assigned at creation, stable, unguessable.
    public string PublicSlug { get; set; } = string.Empty;

    public string Name { get; set; } = "Untitled CV";

    // Optional link to the job application this variant was tailored for. Reference only — deleting
    // the application must not delete the variant (SetNull), and the variant never owns job data.
    public int? JobApplicationId { get; set; }
    public JobApplication? JobApplication { get; set; }

    // Serialized CvVariantSettings — the whole lens (theme, layout, section order/visibility,
    // per-item overrides, builder prefs). One blob because it is edited and saved as a unit and
    // never queried field-by-field, exactly like a version snapshot.
    public string SettingsJson { get; set; } = string.Empty;

    // Public visibility. Off by default; a public variant is served read-only at /cv/{PublicSlug}
    // and is marked noindex.
    public bool IsPublic { get; set; }

    // Autosave version counter (mirrors CareerProfile.Version). Incremented on each saved snapshot.
    public int Version { get; set; }

    public DateTimeOffset CreatedAtUtc { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; }
}

// Append-only autosave history for a variant, so builder edits are reversible. Mirrors
// CareerProfileVersion. Restore re-saves an old snapshot as a new version (non-destructive).
public sealed class CvVariantVersion
{
    public int Id { get; set; }
    public string OwnerUserId { get; set; } = string.Empty;
    public int CvVariantId { get; set; }
    public CvVariant? CvVariant { get; set; }
    public int Version { get; set; }
    public string SettingsJson { get; set; } = string.Empty;
    public string Source { get; set; } = "autosave"; // autosave | manual | restore | create
    public DateTimeOffset CreatedAtUtc { get; set; }
}
