import type { FaqItem, PublicSocialLink } from './public'

export interface AdminMetric {
  label: string
  value: number
  note: string
}

export interface AdminActivity {
  label: string
  age: string
}

export interface AdminTopCategory {
  category: string
  votes: number
}

export interface AdminRiskFlag {
  id: number
  source: string
  type: string
  severity: string
  status: string
  summary: string
  twitchUserId: string | null
  createdFromIp: string
  createdAt: string
  metadataJson: string
  reviewNote: string | null
  reviewedByTwitchId: string | null
  reviewedAt: string | null
  entityLinks: AdminRiskEntityLink[]
}

export interface AdminRiskEntityLink {
  label: string
  entityType: string
  entityId: string
  to: string
}

export interface AdminRiskCount {
  key: string
  count: number
}

export interface AdminRiskFlagsResponse {
  items: AdminRiskFlag[]
  totalCount: number
  returnedCount: number
  offset: number
  limit: number
  hasMore: boolean
  severityCounts: AdminRiskCount[]
  statusCounts: AdminRiskCount[]
}

export interface AdminRiskQueryOptions {
  limit?: number
  offset?: number
  status?: string
  severity?: string
  query?: string
  reviewedOnly?: boolean
}

export interface AdminRiskRule {
  key: string
  label: string
  enabled: boolean
  threshold: number
  windowMinutes: number
  severity: string
  description: string
}

export interface AdminRiskRulesResponse {
  rules: AdminRiskRule[]
}

export interface AdminAuditEntry {
  id: number
  adminTwitchUserId: string
  actionType: string
  entityType: string
  entityId: string
  summary: string
  createdAt: string
  metadataJson: string
  createdFromIp: string | null
  userAgent: string
}

export interface AdminAuditEntriesResponse {
  items: AdminAuditEntry[]
  totalCount: number
  returnedCount: number
  nextCursor: string | null
  limit: number
}

export interface AdminAuditQueryOptions {
  limit?: number
  query?: string
  admin?: string
  action?: string
  entityType?: string
  from?: string
  to?: string
  cursor?: string | null
}

export interface AdminDashboardResponse {
  metrics: AdminMetric[]
  activities: AdminActivity[]
  topCategories: AdminTopCategory[]
  riskFlags: AdminRiskFlag[]
  auditEntries: AdminAuditEntry[]
}

export interface DatabaseHealthResponse {
  provider: string
  canConnect: boolean
  pendingMigrations: string[]
  configuredConnection: {
    source: string
  }
  error?: string | null
}

export interface AdminSeasonListItem {
  id: number
  year: number
  name: string
  currentPhase: string
  isCurrent: boolean
  categoryCount: number
}

export interface AdminCategoryItem {
  id: number
  groupName: string
  name: string
  slug: string
  description: string
  sortOrder: number
  maxNomineesPerUser: number
  candidateCount: number
}

export interface AdminCandidateItem {
  id: number
  categoryId: number
  displayName: string
  channelSlug: string
  platform: string
}

export interface AdminAwardResultItem {
  id: number
  categoryId: number
  categoryName: string
  candidateId: number
  candidateDisplayName: string
  candidateChannelSlug: string
  candidatePlatform: string
}

export interface AdminNominationReviewItem {
  id: number
  categoryId: number
  categoryName: string
  submittedByTwitchId: string
  candidateText: string
  streamUrl: string | null
  status: string
  createdAt: string
  candidateId: number | null
  candidateDisplayName: string | null
  reviewNote: string | null
  reviewedByTwitchId: string | null
  reviewedAt: string | null
}

export interface AdminClipSubmissionItem {
  id: number
  categoryId: number | null
  candidateId: number | null
  submittedByTwitchId: string
  clipUrl: string
  title: string
  creator: string
  platform: string
  status: string
  createdAt: string
  reviewNote: string | null
  reviewedByTwitchId: string | null
  reviewedAt: string | null
}

export interface AdminSeasonDetailResponse {
  id: number
  year: number
  name: string
  showStreamUrl: string
  currentPhase: string
  isCurrent: boolean
  isCommunityOnly: boolean
  nominationStartsAt: string
  nominationEndsAt: string
  votingStartsAt: string
  votingEndsAt: string
  reviewStartsAt: string
  reviewEndsAt: string
  showDate: string
  showStartsAt: string
  categories: AdminCategoryItem[]
  candidates: AdminCandidateItem[]
  pendingNominations: AdminNominationReviewItem[]
  reviewedNominations: AdminNominationReviewItem[]
  results: AdminAwardResultItem[]
  clipSubmissions: AdminClipSubmissionItem[]
}

export interface AdminSiteSettingsResponse {
  hostDisplayName: string
  hostTagline: string
  newsletterUrl: string
  privacyEmail: string
  privacyPolicyContent: string
  privacyPolicyUpdatedBy: string | null
  privacyPolicyUpdatedAt: string | null
  imprintUrl: string
  imprintContent: string
  contactUrl: string
  contactContent: string
  sponsorsUrl: string
  sponsorsContent: string
  socialLinks: PublicSocialLink[]
  faq: FaqItem[]
}

export interface AdminOperationalSettingsResponse {
  demoLoginManagedByDatabase: boolean
  demoLoginEnabled: boolean
  demoLoginEmail: string
  demoLoginPasswordSet: boolean
  demoLoginTwitchUserId: string
  demoLoginDisplayName: string
  twitchAuthManagedByDatabase: boolean
  twitchAuthConfigured: boolean
  twitchClientId: string
  twitchClientSecretSet: boolean
  twitchRedirectUri: string
  twitchScope: string
  maintenanceModeEnabled: boolean
  maintenanceTitle: string
  maintenanceMessage: string
}

export interface AdminTeamPermission {
  key: string
  label: string
  description: string
  menuPath: string
  readOnlySupported: boolean
}

export interface AdminTeamRole {
  key: string
  label: string
  description: string
  isSystemRole: boolean
  permissionKeys: string[]
}

export interface AdminTeamMember {
  id: number
  login: string
  displayName: string
  role: string
  boundTwitchUserId: string | null
  boundTwitchDisplayName: string | null
  isActive: boolean
  mustChangePassword: boolean
  createdAt: string
  updatedAt: string | null
  lastLoginAt: string | null
  lastOnlineAt: string | null
  isOnline: boolean
  twitchBoundAt: string | null
  passwordResetAt: string | null
}

export interface AdminTeamResponse {
  members: AdminTeamMember[]
  roles: AdminTeamRole[]
  permissions: AdminTeamPermission[]
}

export interface CreateTeamMemberPayload {
  login: string
  displayName: string
  role: string
}

export interface UpdateTeamMemberPayload {
  login: string
  displayName: string
  role: string
  isActive: boolean
}

export interface UpdateTeamRolesPayload {
  roles: Array<{
    key: string
    permissionKeys: string[]
  }>
}

export interface TeamMemberPasswordResponse {
  saved: boolean
  memberId: number
  generatedPassword: string
  mustChangePassword: boolean
}
