/**
 * TypeScript types for Settings and AI Control
 */

export interface CleanupReadItems {
  enabled: boolean
  action: 'archive_read' | 'trash'
  gracePeriodDays: number
}

export interface CleanupPromotions {
  enabled: boolean
  matchCategoriesOrLabels: string[]
  action: 'archive_read' | 'trash'
  deleteAfterDays: number
}

export interface CleanupSafety {
  requireConfirmForDelete: boolean
  dryRun?: boolean
  maxDeletesPerRun?: number
}

export interface CleanupSettings {
  enabled: boolean
  readItems: CleanupReadItems
  promotions: CleanupPromotions
  safety: CleanupSafety
}

export interface CategoryAdvanced {
  priority?: 'low' | 'medium' | 'high'
  includeLabels?: string[]
  excludeKeywords?: string[]
}

export interface CleanupStatus {
  lastRun?: string
  lastRunCounts?: {
    readItems: number
    promotions: number
  }
  preview?: Array<{
    id: string
    subject: string
    from: string
    date: string
    reason: 'read' | 'promotion'
  }>
}

export interface AIControlSettings {
  version?: number
  enabledCategories: string[]
  categoryActions: Record<string, 'inbox' | 'archive_read' | 'star'>
  autoDetectCompanies: boolean
  cleanup?: CleanupSettings
  categoryAdvanced?: Record<string, CategoryAdvanced>
}

export interface CompanyLabel {
  id?: string
  name: string
  condition: string
  enabled: boolean
  category?: string
}

/** Name label = personal label per worker (admin only). AI assigns emails to a worker when clearly for them. */
export interface NameLabel {
  id?: string
  name: string
  email?: string
  keywords?: string[]
  enabled: boolean
}

export interface CategoryInfo {
  key: string
  name: string
  description: string
  defaultAction: 'inbox' | 'archive_read' | 'star'
  color: string
  enabled: boolean
}

export interface KnownCompany {
  name: string
  domain: string
  enabled: boolean
}
