import {SessionProps} from "@/lib/types/session";
import {Subscription} from "@/lib/types/user";
import {getCurrentSubscription} from "@/lib/utils/user";

export function getSubLevel(session: SessionProps): number {
    let currentSub: Subscription | null = getCurrentSubscription(session?.user, 'quill-sense');
    if (!currentSub) {
        currentSub = 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;
    }
}

export function isBringYourKeys(session: SessionProps): boolean {
    if (!session?.user) return false;
    const currentSub: Subscription | null = getCurrentSubscription(session?.user, 'use-your-keys');
    return currentSub?.status || session.user.groupId <= 4;
}

export function isGeminiEnabled(session: SessionProps): boolean {
    return session.user?.apiKeys.gemini || false;
}

export function isAnthropicEnabled(session: SessionProps): boolean {
    return session.user?.apiKeys.anthropic || false;
}

export function isOpenAIEnabled(session: SessionProps): boolean {
    return session.user?.apiKeys.openai || false;
}
