import type { Plan, Feature } from '@/types/subscription';
import { PLANS } from './plans';

export function canUseFeature(plan: Plan, feature: Feature): boolean {
  const config = PLANS[plan];
  if (!config) return false;
  return config.features.includes(feature);
}

export function getPlanLimits(plan: Plan) {
  return PLANS[plan]?.limits ?? { maxTasks: 50, maxNotes: 20, maxProjects: 3, maxAiRequestsPerMonth: 10 };
}

export function isAtLimit(plan: Plan, resource: 'tasks' | 'notes' | 'projects', currentCount: number): boolean {
  const limits = getPlanLimits(plan);
  const map = { tasks: limits.maxTasks, notes: limits.maxNotes, projects: limits.maxProjects };
  const limit = map[resource];
  if (limit === null) return false;
  return currentCount >= limit;
}

export function getFeatureLabel(feature: Feature): string {
  const labels: Record<Feature, string> = {
    unlimited_tasks: 'Unbegrenzte Aufgaben',
    unlimited_notes: 'Unbegrenzte Notizen',
    unlimited_projects: 'Unbegrenzte Projekte',
    ai_usage: 'KI-Assistent',
    ai_advanced: 'Erweiterte KI-Features',
    achievements_full: 'Achievements & Belohnungen',
    automation: 'Automationen',
    team_features: 'Team-Funktionen',
    calendar_full: 'Vollständiger Kalender',
    customization_advanced: 'Erweiterte Anpassungen',
    priority_support: 'Priority Support',
  };
  return labels[feature] ?? feature;
}
