import User, {Subscription} from "@/lib/models/User";
import {SessionProps} from "@/lib/models/Session";

export type MessageType = "user" | "model";
export type QSView = 'list' | 'chat' | 'ghostwritter' | 'dictionary' | 'synonyms' | 'conjugator' | 'inspiration'
export type ConversationType = 'dictionary' | 'synonyms' | 'conjugator' | 'chatbot' | 'inspire';

export interface Message {
    id: number;
    type: MessageType;
    message: string;
    date: string;
}

export interface Conversation {
    id: string;
    title?: string;
    date?: string;
    type?: ConversationType;
    messages: Message[];
    status: number;
    totalPrice?: number
    useYourKey?: boolean;
}

export interface AIGeneratedText {
    totalTokens: number;
    totalPrice: number;
    response: string;
}

export interface AIResponseWithCredits<T> {
    useYourKey: boolean;
    totalPrice: number;
    data: T;
}

export interface AIDictionary extends AIResponseWithCredits<DictionaryAIResponse> {
}

export interface AIGeneratedTextData {
    totalCost: number;
    response: string;
}

export interface AIGeneratedText extends AIResponseWithCredits<AIGeneratedTextData> {
}

export interface AIInspire extends AIResponseWithCredits<InspireAIResponse> {
}

export interface AISynonyms extends AIResponseWithCredits<SynonymsAIResponse> {
}

export interface AIVerbConjugation extends AIResponseWithCredits<unknown> {
}

interface InspireAIResponse {
    ideas: {
        idea: string,
        reason: string;
        relatedTo: string;
    }[]
}

export interface DictionaryAIResponse {
    word: string;
    definition: string;
    example: string;
    literaryUsage: string
}

export interface SynonymAI {
    word: string;
    context: string;
}

export interface SynonymsAIResponse {
    words: SynonymAI[];
}

export interface InspirationAIIdea {
    idea: string;
    reason: string;
    relatedTo: string;
}

export interface ConversationProps {
    id: string;
    mode: string;
    title: string;
    startDate: string;
    status: number;
}

export default class QuillSense {
    static getSubLevel(session: SessionProps): number {
        let currentSub: Subscription | null = User.getCurrentSubscription(session?.user, 'quill-sense');
        if (!currentSub) {
            currentSub = User.getCurrentSubscription(session?.user, 'quill-trial');
            if (!currentSub) {
                return 0;
            }
        }
        switch (currentSub?.subTier) {
            case 1:
                return 1;
            case 2:
                return 2;
            case 3:
                return 3;
            default:
                return 0;
        }
    };
    
    static isBringYourKeys(session: SessionProps): boolean {
        if (!session?.user) return false;
        const currentSub: Subscription | null = User.getCurrentSubscription(session?.user, 'use-your-keys');
        return currentSub?.status || session.user.groupId <= 4;
    }
    
    static isGeminiEnabled(session: SessionProps): boolean {
        return session.user?.apiKeys.gemini || false;
    }
    
    static isAnthropicEnabled(session: SessionProps): boolean {
        return session.user?.apiKeys.anthropic || false;
    }
    
    static isOpenAIEnabled(session: SessionProps): boolean {
        return session.user?.apiKeys.openai || false;
    }
}
