import {Author} from './User';
import {ActChapter, ChapterProps} from "@/lib/models/Chapter";
import {SelectBoxProps} from "@/shared/interface";
import {
    BookActSummariesTable,
    BookAIGuideLineTable,
    BookChapterContentTable, BookChapterInfosTable,
    BookChaptersTable, BookCharactersAttributesTable, BookCharactersTable, BookGuideLineTable, BookIncidentsTable,
    BookIssuesTable, BookLocationTable, BookPlotPointsTable, BookWorldElementsTable, BookWorldTable,
    EritBooksTable, LocationElementTable, LocationSubElementTable
} from "@/lib/models/BookTables";
import {
    SyncedActSummary, SyncedAIGuideLine,
    SyncedChapter,
    SyncedCharacter, SyncedGuideLine,
    SyncedIncident, SyncedIssue,
    SyncedLocation,
    SyncedPlotPoint,
    SyncedWorld
} from "@/lib/models/SyncedBook";

export interface CompleteBook {
    eritBooks: EritBooksTable[];
    actSummaries: BookActSummariesTable[];
    aiGuideLine: BookAIGuideLineTable[];
    chapters: BookChaptersTable[];
    chapterContents: BookChapterContentTable[];
    chapterInfos: BookChapterInfosTable[];
    characters: BookCharactersTable[];
    characterAttributes: BookCharactersAttributesTable[];
    guideLine: BookGuideLineTable[];
    incidents: BookIncidentsTable[];
    issues: BookIssuesTable[];
    locations: BookLocationTable[];
    plotPoints: BookPlotPointsTable[];
    worlds: BookWorldTable[];
    worldElements: BookWorldElementsTable[];
    locationElements: LocationElementTable[];
    locationSubElements: LocationSubElementTable[];
}

export interface SyncedBook {
    id: string;
    type: string;
    title: string;
    subTitle: string | null;
    lastUpdate: number;
    chapters: SyncedChapter[];
    characters: SyncedCharacter[];
    locations: SyncedLocation[];
    worlds: SyncedWorld[];
    incidents: SyncedIncident[];
    plotPoints: SyncedPlotPoint[];
    issues: SyncedIssue[];
    actSummaries: SyncedActSummary[];
    guideLine: SyncedGuideLine | null;
    aiGuideLine: SyncedAIGuideLine | null;
}

export interface BookToolsSettings {
    characters: boolean;
    worlds: boolean;
    locations: boolean;
    spells: boolean;
}

export interface BookProps {
    bookId: string;
    type: string;
    title: string;
    author?: Author;
    serie?: number;
    seriesId?: string | null;
    subTitle?: string;
    summary?: string;
    publicationDate?: string;
    desiredWordCount?: number;
    totalWordCount?: number;
    coverImage?: string;
    localBook?: boolean;
    chapters?: ChapterProps[];
    quillsenseEnabled?: boolean;
    tools?: BookToolsSettings;
}

export interface GuideLine {
    tone: string;
    atmosphere: string;
    writingStyle: string;
    themes: string;
    symbolism: string;
    motifs: string;
    narrativeVoice: string;
    pacing: string;
    intendedAudience: string;
    keyMessages: string;
}

export interface GuideLineAI {
    narrativeType: number|null;
    dialogueType: number|null;
    globalResume: string|null;
    atmosphere: string|null;
    verbeTense: number|null;
    langue: number|null;
    currentResume: string|null;
    themes: string|null;
}

export interface PlotPoint {
    plotPointId: string;
    title: string;
    summary: string;
    linkedIncidentId: string;
    chapters?: ActChapter[];
}

export interface Incident {
    incidentId: string;
    title: string;
    summary: string;
    chapters?: ActChapter[];
}

export interface Issue {
    name: string;
    id: string;
}

export interface Act {
    id: number;
    summary: string | null;
    incidents?: Incident[];
    plotPoints?: PlotPoint[];
    chapters?: ActChapter[];
}

export interface Tag {
    label: string,
    value: string,
}

export interface BookTags {
    characters: Tag[];
    locations: Tag[];
    objects: Tag[];
    worldElements: Tag[];
}

export const bookTypes: SelectBoxProps[] = [
    {label: 'bookTypes.short', value: 'short'},
    {label: 'bookTypes.novelette', value: 'novelette'},
    {label: 'bookTypes.novella', value: 'long'},
    {label: 'bookTypes.chapbook', value: 'chapbook'},
    {label: 'bookTypes.novel', value: 'novel'},
]

export default class Book {
    constructor() {
    }

    static booksToSelectBox(books: SyncedBook[]): SelectBoxProps[] {
        return books.map((book: SyncedBook): SelectBoxProps => {
            return {
                label: book.title,
                value: book.id,
            }
        });
    }

    static getBookTypeLabel(value: string): string {
        switch (value) {
            case 'short':
                return 'bookTypes.short';
            case 'novelette':
                return 'bookTypes.novelette';
            case 'long':
                return 'bookTypes.novella';
            case 'chapbook':
                return 'bookTypes.chapbook';
            case 'novel':
                return 'bookTypes.novel';
            default:
                return 'bookTypes.novel';
        }
    }
}
