import type { Plan, PlanConfig } from '@/types/subscription';

export const PLANS: Record<Plan, PlanConfig> = {
  free: {
    id: 'free',
    name: 'Free',
    price: 0,
    priceLabel: '0 €',
    description: 'Für den Einstieg',
    features: ['ai_usage'],
    limits: { maxTasks: 50, maxNotes: 20, maxProjects: 3, maxAiRequestsPerMonth: 10 },
    stripePriceId: null,
  },
  pro: {
    id: 'pro',
    name: 'Pro',
    price: 1500, // cents
    priceLabel: '15 €',
    description: 'Für Produktive',
    features: ['unlimited_tasks','unlimited_notes','unlimited_projects','ai_usage','calendar_full','achievements_full'],
    limits: { maxTasks: null, maxNotes: null, maxProjects: null, maxAiRequestsPerMonth: 200 },
    stripePriceId: process.env.NEXT_PUBLIC_STRIPE_PRO_PRICE_ID ?? null,
  },
  pro_plus: {
    id: 'pro_plus',
    name: 'Pro+',
    price: 2999,
    priceLabel: '29,99 €',
    description: 'Maximale Power',
    highlighted: true,
    badge: 'Empfohlen',
    features: ['unlimited_tasks','unlimited_notes','unlimited_projects','ai_usage','ai_advanced','calendar_full','achievements_full','automation','customization_advanced'],
    limits: { maxTasks: null, maxNotes: null, maxProjects: null, maxAiRequestsPerMonth: 1000 },
    stripePriceId: process.env.NEXT_PUBLIC_STRIPE_PRO_PLUS_PRICE_ID ?? null,
  },
  business: {
    id: 'business',
    name: 'Business',
    price: 4999,
    priceLabel: '49,99 €',
    description: 'Für Teams',
    features: ['unlimited_tasks','unlimited_notes','unlimited_projects','ai_usage','ai_advanced','calendar_full','achievements_full','automation','customization_advanced','team_features'],
    limits: { maxTasks: null, maxNotes: null, maxProjects: null, maxAiRequestsPerMonth: null },
    stripePriceId: process.env.NEXT_PUBLIC_STRIPE_BUSINESS_PRICE_ID ?? null,
  },
  enterprise: {
    id: 'enterprise',
    name: 'Enterprise',
    price: null,
    priceLabel: 'Auf Anfrage',
    description: 'Individuelle Lösung',
    features: ['unlimited_tasks','unlimited_notes','unlimited_projects','ai_usage','ai_advanced','calendar_full','achievements_full','automation','customization_advanced','team_features','priority_support'],
    limits: { maxTasks: null, maxNotes: null, maxProjects: null, maxAiRequestsPerMonth: null },
    stripePriceId: null,
  },
};

export const PLAN_ORDER: Plan[] = ['free','pro','pro_plus','business','enterprise'];

export function getPlanRank(plan: Plan): number {
  return PLAN_ORDER.indexOf(plan);
}

export function isHigherPlan(a: Plan, b: Plan): boolean {
  return getPlanRank(a) > getPlanRank(b);
}
