namespace PlotLine.Models;

public sealed class WordCompanionProjectDto
{
    public int ProjectId { get; set; }
    public string Title { get; set; } = string.Empty;
}

public sealed class WordCompanionProjectsResponse
{
    public IReadOnlyList<WordCompanionProjectDto> Projects { get; init; } = [];
}

public sealed class WordCompanionBookDto
{
    public int BookId { get; set; }
    public string Title { get; set; } = string.Empty;
    public string? Subtitle { get; set; }
    public string DisplayTitle => BookTitleFormatter.DisplayTitle(Title, Subtitle);
    public int SortOrder { get; set; }
    public bool UsesExplicitScenes { get; set; }
}

public sealed class WordCompanionBooksResponse
{
    public IReadOnlyList<WordCompanionBookDto> Books { get; init; } = [];
}

public sealed class WordCompanionSceneStructureDto
{
    public int SceneId { get; set; }
    public string Title { get; set; } = string.Empty;
    public int SortOrder { get; set; }
    public string RevisionStatus { get; set; } = string.Empty;
    public int? EstimatedWords { get; set; }
    public int? ActualWords { get; set; }
}

public sealed class WordCompanionChapterStructureDto
{
    public int ChapterId { get; set; }
    public string Title { get; set; } = string.Empty;
    public int SortOrder { get; set; }
    public IReadOnlyList<WordCompanionSceneStructureDto> Scenes { get; set; } = [];
}

public sealed class WordCompanionBookStructureResponse
{
    public int BookId { get; init; }
    public IReadOnlyList<WordCompanionChapterStructureDto> Chapters { get; init; } = [];
}

public sealed class WordCompanionChaptersResponse
{
    public IReadOnlyList<WordCompanionChapterDto> Chapters { get; init; } = [];
}

public sealed class WordCompanionChapterDto
{
    public int ChapterId { get; init; }
    public string Title { get; init; } = string.Empty;
    public int SortOrder { get; init; }
}

public sealed class WordCompanionResolveSceneRequest
{
    public string? ChapterTitle { get; set; }
    public string? SceneTitle { get; set; }
}

public sealed class WordCompanionResolveSceneResponse
{
    public bool Matched { get; init; }
    public bool ChapterMatched { get; init; }
    public int? ChapterId { get; init; }
    public int? SceneId { get; init; }
    public string? MatchType { get; init; }
    public int? BookId { get; init; }
    public string? ChapterTitleSearched { get; init; }
    public string? SceneTitleSearched { get; init; }
    public int? AvailableChapterCount { get; init; }
    public int? AvailableSceneCount { get; init; }
    public bool BookAccessible { get; init; } = true;
}

public sealed class WordCompanionLinkItemDto
{
    public int CharacterId { get; set; }
    public int AssetId { get; set; }
    public int LocationId { get; set; }
    public string Name { get; set; } = string.Empty;
    public bool Linked { get; set; }
}

public sealed class WordCompanionSceneCompanionResponse
{
    public int SceneId { get; init; }
    public int ChapterId { get; init; }
    public string ChapterTitle { get; init; } = string.Empty;
    public string SceneTitle { get; init; } = string.Empty;
    public int? ActualWords { get; init; }
    public int? EstimatedWords { get; init; }
    public string? WritingBrief { get; init; }
    public bool Blocked { get; init; }
    public string? BlockedReason { get; init; }
    public int? PrimaryLocationId { get; init; }
    public IReadOnlyList<WordCompanionLinkItemDto> Characters { get; init; } = [];
    public IReadOnlyList<WordCompanionLinkItemDto> Assets { get; init; } = [];
    public IReadOnlyList<WordCompanionLinkItemDto> Locations { get; init; } = [];
}

public sealed class WordCompanionSyncSceneRequest
{
    public string? ChapterTitle { get; set; }
    public int? ChapterSortOrder { get; set; }
    public string? SceneTitle { get; set; }
    public int? SceneSortOrder { get; set; }
    public int ActualWords { get; set; }
    public string? DocumentId { get; set; }
    public string? ContentHash { get; set; }
}

public sealed class WordCompanionSyncSceneResponse
{
    public int ChapterId { get; init; }
    public int SceneId { get; init; }
    public bool ChapterCreated { get; init; }
    public bool SceneCreated { get; init; }
    public bool ActualWordsUpdated { get; init; }
    public string Message { get; init; } = "Scene synced successfully.";
}

public sealed class WordCompanionCreateSceneRequest
{
    public string? SceneTitle { get; set; }
}

public sealed class WordCompanionCreateSceneResponse
{
    public int ChapterId { get; init; }
    public int SceneId { get; init; }
    public string Message { get; init; } = "Scene created.";
}

public sealed class WordCompanionCreateChapterRequest
{
    public string? Title { get; set; }
    public int? SortOrder { get; set; }
}

public sealed class WordCompanionCreateChapterResponse
{
    public int ChapterId { get; init; }
    public string Title { get; init; } = string.Empty;
    public int SortOrder { get; init; }
    public string Message { get; init; } = "Chapter created successfully.";
}

public sealed class WordCompanionSyncManuscriptRequest
{
    public string? DocumentId { get; set; }
    public IReadOnlyList<WordCompanionSyncChapterRequest> Chapters { get; set; } = [];
}

public sealed class WordCompanionSyncChapterRequest
{
    public string? Title { get; set; }
    public int? SortOrder { get; set; }
    public int WordCount { get; set; }
    public IReadOnlyList<WordCompanionSyncManuscriptSceneRequest> Scenes { get; set; } = [];
}

public sealed class WordCompanionSyncManuscriptSceneRequest
{
    public string? Title { get; set; }
    public int? SortOrder { get; set; }
    public int WordCount { get; set; }
    public string? ContentHash { get; set; }
}

public sealed class WordCompanionSyncManuscriptResponse
{
    public int ChaptersCreated { get; init; }
    public int ChaptersUpdated { get; init; }
    public int ScenesCreated { get; init; }
    public int ScenesUpdated { get; init; }
    public IReadOnlyList<string> ItemsNotMatched { get; init; } = [];
    public string Message { get; init; } = "Manuscript sync completed.";
}

public sealed class WordCompanionUpdateSceneLinksRequest
{
    public IReadOnlyList<int> CharacterIds { get; set; } = [];
    public IReadOnlyList<int> AssetIds { get; set; } = [];
    public IReadOnlyList<int> LocationIds { get; set; } = [];
    public int? PrimaryLocationId { get; set; }
}

public sealed class WordCompanionUpdateSceneLinksResponse
{
    public int SceneId { get; init; }
    public int CharactersUpdated { get; init; }
    public int AssetsUpdated { get; init; }
    public int LocationsUpdated { get; init; }
    public string Message { get; init; } = "Scene links updated.";
}

public sealed class WordCompanionUpdateWordCountRequest
{
    public int? ActualWords { get; set; }
    public int? ActualWordCount { get; set; }
    public DateTime? LastWorkedOn { get; set; }
}

public sealed class WordCompanionUpdateWordCountResponse
{
    public int SceneId { get; init; }
    public int ActualWords { get; init; }
    public DateTime? LastWorkedOn { get; init; }
    public string Message { get; init; } = "Word count updated.";
}

public sealed class WordCompanionRuntimeSceneWordCountRequest
{
    public Guid DocumentGuid { get; set; }
    public int BookId { get; set; }
    public int ChapterId { get; set; }
    public int SceneId { get; set; }
    public int WordCount { get; set; }
}

public sealed class WordCompanionRuntimeCurrentSceneRequest
{
    public Guid DocumentGuid { get; set; }
    public int ProjectId { get; set; }
    public int BookId { get; set; }
    public int ChapterId { get; set; }
    public int SceneId { get; set; }
}

public sealed class WordCompanionRuntimeCurrentSceneResponse
{
    public int ProjectId { get; init; }
    public int BookId { get; init; }
    public int ChapterId { get; init; }
    public int SceneId { get; init; }
    public string SceneUrl { get; init; } = string.Empty;
}

public sealed class WordCompanionRuntimeCharacterAliasDto
{
    public int CharacterId { get; init; }
    public string Name { get; init; } = string.Empty;
    public string MatchText { get; init; } = string.Empty;
    public bool IsDisplayName { get; init; }
}

public sealed class WordCompanionRuntimeCharacterAliasResponse
{
    public int ProjectId { get; init; }
    public IReadOnlyList<WordCompanionRuntimeCharacterAliasDto> Characters { get; init; } = [];
}

public sealed class WordCompanionRuntimeCharacterSuggestionsRequest
{
    public Guid DocumentGuid { get; set; }
    public int SceneId { get; set; }
    public IReadOnlyList<int> CharacterIds { get; set; } = [];
}

public sealed class WordCompanionRuntimeCharacterSuggestionsResponse
{
    public int SceneId { get; init; }
    public int CreatedCount { get; init; }
    public int SkippedCount { get; init; }
    public string Message { get; init; } = "No new character suggestions.";
}

public sealed class WordCompanionRuntimeAssetAliasDto
{
    public int AssetId { get; init; }
    public string Name { get; init; } = string.Empty;
    public string MatchText { get; init; } = string.Empty;
    public bool IsDisplayName { get; init; }
}

public sealed class WordCompanionRuntimeAssetAliasResponse
{
    public int ProjectId { get; init; }
    public IReadOnlyList<WordCompanionRuntimeAssetAliasDto> Assets { get; init; } = [];
}

public sealed class WordCompanionRuntimeAssetSuggestionsRequest
{
    public Guid DocumentGuid { get; set; }
    public int SceneId { get; set; }
    public IReadOnlyList<int> AssetIds { get; set; } = [];
}

public sealed class WordCompanionRuntimeAssetSuggestionsResponse
{
    public int SceneId { get; init; }
    public int CreatedCount { get; init; }
    public int SkippedCount { get; init; }
    public string Message { get; init; } = "No new asset suggestions.";
}

public sealed class WordCompanionRuntimeLocationAliasDto
{
    public int LocationId { get; init; }
    public int? ParentLocationId { get; init; }
    public string Name { get; init; } = string.Empty;
    public string LocationPath { get; init; } = string.Empty;
    public string MatchText { get; init; } = string.Empty;
    public bool IsDisplayName { get; init; }
    public bool ExcludeFromCompanionDetection { get; init; }
    public int DetectionPriority { get; init; } = 50;
}

public sealed class WordCompanionRuntimeLocationAliasResponse
{
    public int ProjectId { get; init; }
    public IReadOnlyList<WordCompanionRuntimeLocationAliasDto> Locations { get; init; } = [];
}

public sealed class WordCompanionRuntimeLocationSuggestionsRequest
{
    public Guid DocumentGuid { get; set; }
    public int SceneId { get; set; }
    public IReadOnlyList<int> LocationIds { get; set; } = [];
}

public sealed class WordCompanionRuntimeLocationSuggestionsResponse
{
    public int SceneId { get; init; }
    public int CreatedCount { get; init; }
    public int SkippedCount { get; init; }
    public string Message { get; init; } = "No new location suggestions.";
}

public sealed class WordCompanionManuscriptDocumentDto
{
    public int ManuscriptDocumentId { get; init; }
    public int BookId { get; init; }
    public int ProjectId { get; init; }
    public Guid DocumentGuid { get; init; }
    public int BindingVersion { get; init; }
    public DateTime CreatedUtc { get; init; }
    public DateTime? LastSyncUtc { get; init; }
    public DateTime? LastOpenedUtc { get; init; }
    public bool IsActive { get; init; }
}

public sealed class WordCompanionManuscriptBookResponse
{
    public int BookId { get; init; }
    public WordCompanionManuscriptDocumentDto? ManuscriptDocument { get; init; }
}

public sealed class WordCompanionRuntimeBookResponse
{
    public int ProjectId { get; init; }
    public string ProjectTitle { get; init; } = string.Empty;
    public int BookId { get; init; }
    public string BookTitle { get; init; } = string.Empty;
    public string? BookSubtitle { get; init; }
    public bool UsesExplicitScenes { get; init; }
    public DateTime? LastSyncUtc { get; init; }
    public WordCompanionManuscriptDocumentDto ManuscriptDocument { get; init; } = new();
}

public sealed class WordCompanionManuscriptLinkRequest
{
    public int BookId { get; set; }
    public Guid? DocumentGuid { get; set; }
}

public sealed class WordCompanionManuscriptLinkResponse
{
    public int BookId { get; init; }
    public WordCompanionManuscriptDocumentDto ManuscriptDocument { get; init; } = new();
    public string Message { get; init; } = "Manuscript linked.";
}

public sealed class WordCompanionManuscriptUnlinkRequest
{
    public int BookId { get; set; }
    public Guid? DocumentGuid { get; set; }
}

public sealed class WordCompanionManuscriptUnlinkResponse
{
    public int BookId { get; init; }
    public int ManuscriptDocumentId { get; init; }
    public int ChaptersUnlinked { get; init; }
    public int ScenesUnlinked { get; init; }
    public string Message { get; init; } = "Manuscript unlinked.";
}

public sealed class WordCompanionCreateBookRequest
{
    public string? Title { get; set; }
}

public sealed class WordCompanionCreateBookResponse
{
    public int BookId { get; init; }
    public string Title { get; init; } = string.Empty;
    public string? Subtitle { get; init; }
    public int SortOrder { get; init; }
    public bool UsesExplicitScenes { get; init; }
    public string Message { get; init; } = "Book created.";
}

public sealed class WordCompanionManuscriptImportSceneRequest
{
    public string? Title { get; set; }
    public int? SortOrder { get; set; }
    public int WordCount { get; set; }
}

public sealed class WordCompanionManuscriptImportChapterRequest
{
    public string? Title { get; set; }
    public int? SortOrder { get; set; }
    public int WordCount { get; set; }
    public IReadOnlyList<WordCompanionManuscriptImportSceneRequest> Scenes { get; set; } = [];
}

public sealed class WordCompanionManuscriptAnalyseRequest
{
    public int ProjectId { get; set; }
    public int BookId { get; set; }
    public Guid? DocumentGuid { get; set; }
    public int ChapterCount { get; set; }
    public int SceneCount { get; set; }
    public int WordCount { get; set; }
}

public sealed class WordCompanionManuscriptAnalyseResponse
{
    public int ProjectId { get; init; }
    public int BookId { get; init; }
    public string ProjectTitle { get; init; } = string.Empty;
    public string BookTitle { get; init; } = string.Empty;
    public string? BookSubtitle { get; init; }
    public bool UsesExplicitScenes { get; init; }
    public int ChapterCount { get; init; }
    public int SceneCount { get; init; }
    public int WordCount { get; init; }
    public int ExistingChapterCount { get; init; }
    public int ExistingSceneCount { get; init; }
    public int LinkedChapterCount { get; init; }
    public bool CanImport { get; init; }
    public bool RequiresReplaceConfirmation { get; init; }
    public string Message { get; init; } = string.Empty;
}

public sealed class WordCompanionManuscriptImportRequest
{
    public int ProjectId { get; set; }
    public int BookId { get; set; }
    public Guid? DocumentGuid { get; set; }
    public int BindingVersion { get; set; } = 1;
    public bool ReplacePlanned { get; set; }
    public IReadOnlyList<WordCompanionManuscriptImportChapterRequest> Chapters { get; set; } = [];
}

public sealed class WordCompanionManuscriptImportResponse
{
    public bool Imported { get; init; }
    public bool RequiresReplaceConfirmation { get; init; }
    public string Message { get; init; } = string.Empty;
    public int ProjectId { get; init; }
    public int BookId { get; init; }
    public int ChaptersCreated { get; init; }
    public int ScenesCreated { get; init; }
    public int ArchivedChapters { get; init; }
    public int ArchivedScenes { get; init; }
    public WordCompanionManuscriptDocumentDto? ManuscriptDocument { get; init; }
}

public sealed class WordCompanionCharacterCandidateDto
{
    public string Text { get; init; } = string.Empty;
    public int MentionCount { get; init; }
    public string Confidence { get; init; } = "Medium";
    public int QualityScore { get; init; }
    public string Category { get; init; } = "PossibleCharacter";
    public string Reason { get; init; } = string.Empty;
    public bool IsExistingCharacterMatch { get; init; }
}

public sealed class WordCompanionDiscoverCharactersRequest
{
    public int ProjectId { get; set; }
    public string? DocumentText { get; set; }
    public bool IncludeExcluded { get; set; }
}

public sealed class WordCompanionDiscoverCharactersResponse
{
    public int ProjectId { get; init; }
    public IReadOnlyList<WordCompanionCharacterCandidateDto> Candidates { get; init; } = [];
}

public sealed class WordCompanionCreateDiscoveredCharactersRequest
{
    public int ProjectId { get; set; }
    public IReadOnlyList<string> CandidateNames { get; set; } = [];
}

public sealed class WordCompanionCreatedCharacterDto
{
    public int CharacterId { get; init; }
    public string Name { get; init; } = string.Empty;
    public bool Created { get; init; }
}

public sealed class WordCompanionCreateDiscoveredCharactersResponse
{
    public int ProjectId { get; init; }
    public int CreatedCount { get; init; }
    public int SkippedCount { get; init; }
    public IReadOnlyList<WordCompanionCreatedCharacterDto> Characters { get; init; } = [];
    public string Message { get; init; } = "Characters created.";
}
