// Admin approval workflow types

export interface AdminFeature {
  id: string;
  template_id: string;
  name: string;
  description?: string;
  complexity: 'low' | 'medium' | 'high';
  business_rules?: any;
  technical_requirements?: any;
  approved: boolean;
  usage_count: number;
  created_by_user_session?: string;
  created_at: string;
  updated_at: string;
  // Admin workflow fields
  status: 'pending' | 'approved' | 'rejected' | 'duplicate';
  admin_notes?: string;
  admin_reviewed_at?: string;
  admin_reviewed_by?: string;
  canonical_feature_id?: string;
  similarity_score?: number;
  // Additional fields from joins
  template_title?: string;
}

export interface AdminNotification {
  id: string;
  type: string;
  message: string;
  reference_id?: string;
  reference_type?: string;
  is_read: boolean;
  created_at: string;
  read_at?: string;
}

export interface FeatureSimilarity {
  id: string;
  name: string;
  match_type: 'exact' | 'synonym' | 'fuzzy';
  score: number;
  feature_type: string;
  complexity: string;
}

export interface DuplicateCheckResult {
  isDuplicate: boolean;
  canonicalFeature?: FeatureSimilarity;
  similarityScore?: number;
  matchType?: string;
}

export interface FeatureReviewData {
  status: 'approved' | 'rejected' | 'duplicate';
  notes?: string;
  canonical_feature_id?: string;
  admin_reviewed_by: string;
}

export interface FeatureStats {
  status: string;
  count: number;
}

export interface NotificationCounts {
  total: number;
  unread: number;
  read: number;
}

export interface AdminStats {
  features: FeatureStats[];
  notifications: NotificationCounts;
}

export interface FeatureSynonym {
  id: string;
  feature_id: string;
  synonym: string;
  created_by?: string;
  created_at: string;
}

// API Response types
export interface AdminApiResponse<T> {
  success: boolean;
  data: T;
  count?: number;
  message: string;
  error?: string;
}

export interface FeatureSubmissionResponse {
  success: boolean;
  data: AdminFeature;
  message: string;
  similarityInfo?: DuplicateCheckResult;
}

// Admin dashboard state
export interface AdminDashboardState {
  pendingFeatures: AdminFeature[];
  notifications: AdminNotification[];
  stats: AdminStats | null;
  loading: boolean;
  error: string | null;
}

// Admin filters and pagination
export interface AdminFilters {
  status?: 'pending' | 'approved' | 'rejected' | 'duplicate';
  search?: string;
  complexity?: 'low' | 'medium' | 'high';
}

export interface AdminPagination {
  page: number;
  limit: number;
  total: number;
}

export interface AdminTemplate {
  id: string;
  type: string;
  title: string;
  description?: string;
  icon?: string;
  category?: string;
  gradient?: string;
  border?: string;
  text?: string;
  subtext?: string;
  complexity: 'low' | 'medium' | 'high';
  business_rules?: Record<string, unknown>;
  technical_requirements?: Record<string, unknown>;
  approved: boolean;
  usage_count: number;
  created_by_user_session?: string;
  created_at: string;
  updated_at: string;
  is_custom: boolean;
  // Admin approval workflow fields
  status: 'pending' | 'approved' | 'rejected' | 'duplicate';
  admin_notes?: string;
  admin_reviewed_at?: string;
  admin_reviewed_by?: string;
  canonical_template_id?: string;
  similarity_score?: number;
  user_id?: string;
}
