namespace PlotLine.ViewModels;

public sealed class StoryIntelligenceExperiencePrototypeViewModel
{
    public string Mode { get; init; } = "simulation";
    public int? RunId { get; init; }
    public int? ImportSessionId { get; init; }
    public int? BookId { get; init; }
    public string? RunStatus { get; init; }
    public string? ChangeToken { get; init; }
    public DateTime GeneratedUtc { get; init; } = DateTime.UtcNow;
    public bool IsTerminal { get; init; }
    public string? SnapshotMessage { get; init; }
    public StoryIntelligenceExperienceSnapshotDiagnostics Diagnostics { get; init; } = new();
    public IReadOnlyList<StoryIntelligenceExperienceRunOption> AvailableRuns { get; init; } = [];
    public string ProjectName { get; init; } = string.Empty;
    public string BookTitle { get; init; } = string.Empty;
    public IReadOnlyList<StoryIntelligenceExperienceSceneState> Scenes { get; init; } = [];
}

public sealed class StoryIntelligenceExperienceSnapshotDiagnostics
{
    public string RequestedMode { get; init; } = string.Empty;
    public int? CurrentImportId { get; init; }
    public int? RequestedImportSessionId { get; init; }
    public int? ResolvedImportSessionId { get; init; }
    public int? ActiveChapterRunId { get; init; }
    public string SessionStatus { get; init; } = string.Empty;
    public int OverallBookProgress { get; init; }
    public int AuthoritativeImportProgress { get; init; }
    public int CalculatedVisualisationProgress { get; init; }
    public int TotalChapters { get; init; }
    public int CompletedChapters { get; init; }
    public string CurrentChapter { get; init; } = string.Empty;
    public string CurrentScene { get; init; } = string.Empty;
    public int CompletedScenes { get; init; }
    public int TotalScenes { get; init; }
    public int ParsedScenes { get; init; }
    public string TerminalRunSessionStatus { get; init; } = string.Empty;
    public string DisplayedProgressReason { get; init; } = string.Empty;
    public string ProgressSource { get; init; } = string.Empty;
    public string CurrentBackendStage { get; init; } = string.Empty;
    public int StoryMemoryCharacterCount { get; init; }
    public int ResolvedCharacterCount { get; init; }
    public int UnresolvedCharacterCount { get; init; }
    public decimal NarratorConfidence { get; init; }
    public int IllustrationAssignmentCount { get; set; }
    public int IllustrationChangeCount { get; set; }
    public string CharacterConsistencyReport { get; set; } = string.Empty;
    public string RawScenePov { get; init; } = string.Empty;
    public string InheritedChapterPov { get; init; } = string.Empty;
    public string ResolvedPovIdentity { get; init; } = string.Empty;
    public string PovResolutionReason { get; init; } = string.Empty;
    public decimal PovConfidence { get; init; }
    public bool PovChangeDetected { get; init; }
    public string SnapshotSource { get; init; } = string.Empty;
    public string RunStatus { get; init; } = string.Empty;
    public int PersistedCompletedSceneCount { get; init; }
    public int TotalPersistedSceneResultCount { get; init; }
    public int SuccessfullyParsedSceneResultCount { get; init; }
    public int FailedSceneResultCount { get; init; }
    public int? HighestPersistedSceneResultId { get; init; }
    public int? HighestParsedSceneResultId { get; init; }
    public int? SelectedCurrentSceneResultId { get; init; }
    public string SelectedChapterAndSceneOrder { get; init; } = string.Empty;
    public string CurrentChangeToken { get; init; } = string.Empty;
    public string? AnalysisCursor { get; init; }
    public string? Warning { get; init; }
    public int ReplayIndex { get; init; }
    public int TotalReplayableScenes { get; init; }
    public string ReplayMilestone { get; init; } = string.Empty;
    public string ReplayState { get; init; } = string.Empty;
    public string SnapshotCacheStatus { get; init; } = string.Empty;
    public string RebuildVersion { get; init; } = string.Empty;
    public string AppearancePreference { get; init; } = string.Empty;
    public int FailedChaptersSkipped { get; init; }
    public string FailedChapterSummary { get; init; } = string.Empty;
    public string PanelVisibleCounts { get; init; } = string.Empty;
    public string PanelHiddenCounts { get; init; } = string.Empty;
    public int AiCallsDuringReplay { get; init; }
}

public sealed class StoryIntelligenceExperienceRunOption
{
    public int RunId { get; init; }
    public int? ImportSessionId { get; init; }
    public string Label { get; init; } = string.Empty;
    public string Status { get; init; } = string.Empty;
    public DateTime CreatedUtc { get; init; }
}

public sealed class StoryIntelligenceExperienceSceneState
{
    public string Id { get; init; } = string.Empty;
    public bool IsCurrent { get; init; }
    public int? ChapterRunId { get; init; }
    public decimal? ChapterNumber { get; init; }
    public int? SceneResultId { get; init; }
    public int ReplayIndex { get; init; }
    public int GlobalSceneIndex { get; init; }
    public string ChapterLabel { get; init; } = string.Empty;
    public int SceneNumber { get; init; }
    public string Title { get; init; } = string.Empty;
    public string Summary { get; init; } = string.Empty;
    public string Stage { get; init; } = string.Empty;
    public string TimelineLabel { get; init; } = string.Empty;
    public string TimelineEvent { get; init; } = string.Empty;
    public int ProgressPercent { get; init; }
    public int ChaptersAnalysed { get; init; }
    public int ChapterTotal { get; init; }
    public int ScenesAnalysed { get; init; }
    public int SceneTotal { get; init; }
    public string ElapsedTime { get; init; } = string.Empty;
    public string EstimatedRemaining { get; init; } = string.Empty;
    public string PovCharacterId { get; init; } = string.Empty;
    public StoryIntelligenceExperienceLocationState Location { get; init; } = new();
    public IReadOnlyList<StoryIntelligenceExperienceCharacterState> Characters { get; init; } = [];
    public IReadOnlyList<StoryIntelligenceExperienceAssetState> Assets { get; init; } = [];
    public IReadOnlyList<StoryIntelligenceExperienceRelationshipState> Relationships { get; init; } = [];
    public IReadOnlyList<StoryIntelligenceExperienceTextItem> KnowledgeThreads { get; init; } = [];
    public IReadOnlyList<StoryIntelligenceExperienceTextItem> Observations { get; init; } = [];
    public IReadOnlyList<string> LatestDiscoveries { get; init; } = [];
    public IReadOnlyList<string> ActivityFeed { get; init; } = [];
}

public sealed class StoryIntelligenceExperienceCharacterState
{
    public string Id { get; init; } = string.Empty;
    public string LibraryCode { get; set; } = string.Empty;
    public string Name { get; init; } = string.Empty;
    public string Role { get; init; } = string.Empty;
    public string Relevance { get; init; } = string.Empty;
    public int Weight { get; init; }
    public string ImagePath { get; set; } = string.Empty;
    public StoryIntelligenceExperienceImageResolution ImageResolution { get; set; } = new();
}

public sealed class StoryIntelligenceExperienceLocationState
{
    public string Id { get; init; } = string.Empty;
    public string LibraryCode { get; set; } = string.Empty;
    public string Name { get; init; } = string.Empty;
    public string Label { get; init; } = string.Empty;
    public string ImagePath { get; set; } = string.Empty;
    public StoryIntelligenceExperienceImageResolution ImageResolution { get; set; } = new();
}

public sealed class StoryIntelligenceExperienceAssetState
{
    public string Id { get; init; } = string.Empty;
    public string LibraryCode { get; set; } = string.Empty;
    public string Name { get; init; } = string.Empty;
    public string Label { get; init; } = string.Empty;
    public int Weight { get; init; }
    public string ImagePath { get; set; } = string.Empty;
    public StoryIntelligenceExperienceImageResolution ImageResolution { get; set; } = new();
}

public sealed class StoryIntelligenceExperienceImageResolution
{
    public string EntityId { get; init; } = string.Empty;
    public string StableCode { get; init; } = string.Empty;
    public int? IllustrationLibraryItemId { get; init; }
    public string? Status { get; init; }
    public string? FinalImageUrl { get; init; }
    public string FallbackImageUrl { get; init; } = string.Empty;
    public bool FallbackUsed { get; init; } = true;
    public decimal? AssignmentConfidence { get; init; }
    public int? MatchingScore { get; init; }
    public string? RejectedCandidates { get; set; }
    public string? ReasonChosen { get; set; }
    public string? ReasonReassigned { get; set; }
    public string? PreviousIllustration { get; set; }
    public string? PreviousEvidence { get; set; }
    public string? CurrentEvidence { get; set; }
    public string? DemandKey { get; set; }
    public string? EvidenceWarnings { get; set; }
    public string? DemandStatus { get; set; }
    public string? ResolvedPresentation { get; init; }
    public string? ResolvedAgeBand { get; init; }
    public decimal? RelationshipDerivedConfidence { get; init; }
    public decimal? NameDerivedConfidence { get; init; }
    public decimal? PronounDerivedConfidence { get; init; }
    public int? IllustrationReuseCount { get; init; }
    public string? IllustrationAllocationStatus { get; init; }
}

public sealed class StoryIntelligenceExperienceRelationshipState
{
    public string Id { get; init; } = string.Empty;
    public string SourceId { get; init; } = string.Empty;
    public string TargetId { get; init; } = string.Empty;
    public string Label { get; init; } = string.Empty;
    public string State { get; init; } = string.Empty;
    public int Weight { get; init; }
}

public sealed class StoryIntelligenceExperienceTextItem
{
    public string Id { get; init; } = string.Empty;
    public string Title { get; init; } = string.Empty;
    public string Detail { get; init; } = string.Empty;
    public string Tone { get; init; } = string.Empty;
}
