// Shared TypeScript types across the monorepo

export type UserRole = 'GUEST' | 'MEMBER' | 'PREMIUM' | 'ADMIN';
export type SubscriptionTier = 'FREE' | 'BASIC' | 'PRO' | 'LIFETIME';
export type SubscriptionStatus = 'ACTIVE' | 'CANCELED' | 'PAST_DUE' | 'TRIALING' | 'INACTIVE';
export type PlanDuration = 'THREE_DAYS' | 'SEVEN_DAYS' | 'FOURTEEN_DAYS' | 'THIRTY_DAYS';
export type ProductCategory = 'SUPPLEMENTS' | 'SNACKS' | 'INGREDIENTS' | 'EQUIPMENT' | 'BOOKS' | 'OTHER';
export type OrderStatus = 'PENDING' | 'COMPLETED' | 'REFUNDED' | 'FAILED';
export type DiscountType = 'PERCENTAGE' | 'FIXED';

export interface ApiUser {
  id: string;
  email: string;
  name?: string;
  avatarUrl?: string;
  role: UserRole;
  subscriptionTier: SubscriptionTier;
  subscriptionStatus: SubscriptionStatus;
  subscriptionEndsAt?: string;
  streakCount: number;
  totalPoints: number;
}

export interface ApiPlan {
  id: string;
  slug: string;
  title: string;
  description: string;
  shortDesc: string;
  duration: PlanDuration;
  price: number;
  tier: 'FREE' | 'PAID' | 'PREMIUM_ONLY';
  featured: boolean;
  published: boolean;
  imageUrl?: string;
  purchaseCount: number;
  avgRating: number;
  reviewCount: number;
  meals?: any;
  shoppingList?: any;
  nutritionInfo?: any;
  pdfUrl?: string;
}

export interface ApiProduct {
  id: string;
  slug: string;
  name: string;
  description: string;
  imageUrl?: string;
  affiliateUrl: string;
  priceDisplay?: string;
  category: ProductCategory;
  tags: string[];
  featured: boolean;
  clickCount: number;
}

export interface ApiMacros {
  calories: number;
  proteinG: number;
  fatG: number;
  carbsG?: number;
  netCarbsG: number;
}

export interface AiMealPlan {
  summary: string;
  dailyMacros: ApiMacros;
  days: AiDay[];
  shoppingList: Record<string, string[]>;
  tips: string[];
}

export interface AiDay {
  day: number;
  meals: {
    breakfast: AiMeal;
    lunch: AiMeal;
    dinner: AiMeal;
    snack: AiMeal;
  };
}

export interface AiMeal {
  name: string;
  description: string;
  calories: number;
  proteinG: number;
  fatG: number;
  netCarbsG: number;
}

export const DURATION_LABEL: Record<PlanDuration, string> = {
  THREE_DAYS: '3 Days',
  SEVEN_DAYS: '7 Days',
  FOURTEEN_DAYS: '14 Days',
  THIRTY_DAYS: '30 Days',
};

export const SUBSCRIPTION_FEATURES: Record<SubscriptionTier, string[]> = {
  FREE: ['1 AI plan/week', 'Basic tracker', 'Free 3-day plan'],
  BASIC: ['All plans', 'Full tracker', 'PDF downloads'],
  PRO: ['Unlimited AI', 'All plans', 'PDF export', 'Streak freeze'],
  LIFETIME: ['Everything in Pro', 'All future plans', 'VIP access'],
};
