
export enum UserRole {
  ADMIN = 'ADMIN',   // Internal Super User
  VENDOR = 'VENDOR', // External Vendor
  EDITOR = 'EDITOR',  // Internal Staff/Manager
  CUSTOMER = 'CUSTOMER' // End User
}

export type Theme = 'royal' | 'midnight' | 'rose' | 'forest' | 'neon';

export interface AIAttributeConfig {
  key: string;
  label: string;
  values: string[];
  description?: string;
  category?: 'USER_DNA' | 'NEED_DNA';
  mode?: 'QUICK' | 'DEEP' | 'BOTH';
  sortOrder?: number;
  required?: boolean;
  helperText?: string;
  curiosityPrompt?: string;
  weight?: number;
  dependsOnKey?: string;
  dependsOnValue?: string;
}

export interface QuestionnaireStatus {
  quickTotal: number;
  quickAnswered: number;
  deepTotal: number;
  deepAnswered: number;
  profileCompletion: number;
  quickCompleted: boolean;
  deepCompleted: boolean;
  requiresOnboarding: boolean;
}

export interface BarcodeSegment {
  category: string;
  value: string;
  percentage: number;
  color: string;
}

export interface Barcode {
  segments: BarcodeSegment[];
}

export interface User {
  id: string;
  name: string;
  email: string;
  role: UserRole;
  storeName?: string; // Only for vendors
  avatarUrl?: string;
  status: 'ACTIVE' | 'SUSPENDED';
  joinedAt: string;
  createdAt?: string; // Compatibility
  phone?: string;
  address?: string;
  preferences?: Record<string, any>;
  personalBarcode?: Barcode;
  questionnaireStatus?: QuestionnaireStatus;
}

export enum ProductStatus {
  DRAFT = 'DRAFT',
  PUBLISHED = 'PUBLISHED',
  ARCHIVED = 'ARCHIVED'
}

export interface Variant {
  id: string;
  sku: string;
  name: string; // e.g., "50ml", "100ml"
  size?: string; // Compatibility
  price: number;
  stock: number;
  lowStockThreshold?: number; // Alert when stock is below this
  weight?: string;
}

export interface FragranceNotes {
  top: string[];
  middle: string[];
  base: string[];
}

// New Interface for the detailed graph data
export interface AIGraphData {
  [key: string]: Record<string, number> | string | undefined;
  perfume_name?: string;
}

export interface Product {
  id: string;
  vendorId: string;
  vendorName?: string; // Populated for Admins
  
  // Database Schema Updates
  productName: string;
  brandName: string;
  description: string;
  
  category: string;
  images: string[];
  status: ProductStatus;
  variants: Variant[];
  fragranceNotes?: FragranceNotes;
  concentration: 'Parfum' | 'EDP' | 'EDT' | 'Cologne' | 'Other';
  
  // AI Batching & Detailed Characteristics
  aiBatchStatus?: 'PENDING' | 'COMPLETED' | 'FAILED';
  
  // New Complex Data Structure
  aiData?: AIGraphData;
  aiAttributes?: any; // Compatibility
  productDNA?: any;
  
  // Semantic Search
  distance?: number; // Lower is better (0 = exact match)
  isNew?: boolean;
  isFeatured?: boolean; // Compatibility
  gender?: string; // Compatibility

  // Keeping these for backward compatibility/fallback display if needed, 
  // but aiData is the primary source now.
  barcode?: Barcode;
  
  createdAt: string;
  updatedAt: string;
}

export interface RecommendationExplainability {
  userDNA: string[];
  needDNA: string[];
  productIntelligence: string[];
  summary: string;
  whyChosen?: string[];
  whyBetterThanOthers?: string[];
  whyTrustThisRecommendation?: string[];
  whyNow?: string[];
  confidenceLabel?: 'Safe' | 'Perfect' | 'Bold' | 'Balanced';
}

export interface ScoredRecommendation extends Product {
  recommendationScore?: number;
  matchPercentage?: number;
  userDNAScore?: number;
  needDNAScore?: number;
  productIntelligenceScore?: number;
  embeddingScore?: number;
  barcodeMatchScore?: number;
  boldnessScore?: number;
  safeScore?: number;
  explainability?: RecommendationExplainability;
}

export interface RecommendationBuckets {
  safePick: ScoredRecommendation | null;
  perfectPick: ScoredRecommendation | null;
  boldPick: ScoredRecommendation | null;
  safeMatches?: ScoredRecommendation[];
  perfectMatches?: ScoredRecommendation[];
  boldMatches?: ScoredRecommendation[];
  moreMatches: ScoredRecommendation[];
  all: ScoredRecommendation[];
}

export interface ToolNarrative {
  headline: string;
  summary: string;
  bullets: string[];
}

export interface GiftGenieResponse {
  hero: ScoredRecommendation | null;
  alternatives: ScoredRecommendation[];
  narrative?: ToolNarrative;
}

export interface CoupleSyncResponse {
  safePick: ScoredRecommendation | null;
  perfectPick: ScoredRecommendation | null;
  boldPick: ScoredRecommendation | null;
  alternatives: ScoredRecommendation[];
  relationshipIntent: string;
  personA: Record<string, string[]>;
  personB: Record<string, string[]>;
  narrative?: ToolNarrative;
}

export interface ScentCompareResponse {
  winner: ScoredRecommendation | null;
  products: ScoredRecommendation[];
  narrative?: ToolNarrative;
}

export interface WardrobeSlot {
  key: string;
  title: string;
  context: string;
  product: ScoredRecommendation | null;
  why: string[];
}

export interface ScentWardrobeResponse {
  wardrobe: WardrobeSlot[];
  alternatives: ScoredRecommendation[];
  narrative?: ToolNarrative;
}

export interface EventStylistResponse {
  hero: ScoredRecommendation | null;
  sceneSetters: ScoredRecommendation[];
  eventProfile: {
    eventType: string;
    venue: string;
    dressCode: string;
    climate: string;
    impression: string;
  };
  narrative?: ToolNarrative;
}

export interface ScentComposerResponse {
  hero: ScoredRecommendation | null;
  alternatives: ScoredRecommendation[];
  composition: {
    headline: string;
    accords: string[];
    moodWords: string[];
    signatureDirection: string[];
  };
  narrative?: ToolNarrative;
}

export interface EchoSphereResponse {
  innerCircle: ScoredRecommendation[];
  expandingOrbit: ScoredRecommendation[];
  contrastEcho: ScoredRecommendation | null;
  echoProfile: {
    dominantFamilies: string[];
    dominantTraits: string[];
    dominantOccasions: string[];
  };
  narrative?: ToolNarrative;
}

export interface EvolutionEngineResponse {
  topBrands: { brand: string; score: number }[];
  topFamilies: { family: string; score: number }[];
  topTraits?: { trait: string; score: number }[];
  topOccasions?: { occasion: string; score: number }[];
  signalCounts?: Record<string, number>;
  evolutionSummary?: {
    profileMomentum: 'early' | 'building' | 'strong' | 'mature';
    strongestPositiveSignal: string;
    strongestCautionSignal?: string;
    learnedTasteSummary: string[];
  };
  recentEvents: { event_type: string; product_id: string; metadata?: any; created_at: string }[];
  refinedRecommendations: RecommendationBuckets;
  narrative?: ToolNarrative;
}

export interface Channel {
  id: string;
  vendorId: string;
  name: string; // e.g., "Shopify", "Custom React Store"
  type: 'CUSTOM_API' | 'SHOPIFY' | 'WOOCOMMERCE';
  apiKey: string;
  apiSecret?: string;
  webhookUrl?: string;
  status: 'ACTIVE' | 'INACTIVE';
  connectedAt: string;
}

export interface DashboardStats {
  totalProducts: number;
  totalStock: number;
  activeVariants: number;
  pendingOrders: number;
  revenue: number[];
  topVendors?: { name: string; revenue: number }[]; // Admin only
  channelHealth?: number; // % of active channels
}

export enum OrderStatus {
  PENDING = 'PENDING',
  PROCESSING = 'PROCESSING',
  SHIPPED = 'SHIPPED',
  DELIVERED = 'DELIVERED',
  CANCELLED = 'CANCELLED'
}

export interface OrderItem {
  productId: string;
  variantId: string;
  productName: string;
  variantName: string;
  quantity: number;
  price: number;
  image?: string;
}

export interface Order {
  id: string;
  orderNumber: string;
  vendorId: string;
  vendorName?: string; // Compatibility
  customerName: string;
  customerEmail: string;
  items: OrderItem[];
  total: number;
  totalAmount?: number; // Compatibility
  status: OrderStatus;
  shippingAddress: string;
  createdAt: string;
  orderDate?: string; // Compatibility
}

export interface LogEntry {
  id: number;
  level: 'INFO' | 'WARN' | 'ERROR' | 'SUCCESS';
  source: string;
  message: string;
  timestamp: string;
}
