export interface User {
  id: number
  username: string
  display_name: string
  role: 'admin' | 'pm' | 'engineer' | 'customer'
  is_active: boolean
  email?: string
}

export interface Server {
  id: number
  hostname: string
  os_type: string
  status: 'running' | 'stopped' | 'error' | 'unknown'
  inst_id?: number
  inst_name?: string
}

export interface SRRequest {
  id: number
  sr_id: string
  title: string
  status: string
  priority: 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW'
  requested_by: string
  assigned_to?: string
  created_at: string
}

export interface DashboardStats {
  total_tasks: number
  open_tasks: number
  in_progress_tasks: number
  completed_today: number
  critical_count: number
  pending_approvals: number
}

export interface APIKey {
  id: number
  name: string
  scopes: string
  allowed_ips: string
  is_active: boolean
  use_count: number
  last_used_at: string | null
  expires_at: string | null
  created_by: string
  created_at: string
}

export interface AuditEntry {
  id: number
  action: string
  entity_type: string
  entity_id: string
  username: string
  ip_hash: string
  created_at: string
  detail?: string
}

export interface SystemResources {
  cpu_percent: number
  memory: { total_gb: number; used_gb: number; percent: number }
  disk:   { total_gb: number; used_gb: number; percent: number }
}

export interface ServiceStatus {
  [name: string]: 'active' | 'inactive' | 'failed' | 'unknown'
}

export interface OllamaModel {
  name: string
  size: number
  modified_at: string
  details?: { parameter_size?: string; family?: string }
}

export interface GitRepo {
  id: number
  name: string
  full_name: string
  description: string
  updated_at: string
  clone_url: string
}

export interface DeployLogLine {
  time: string
  level: string
  msg: string
  ok: boolean
}

/* ── 라이선스 ── */
export type LicenseEdition = 'TRIAL' | 'COMMUNITY' | 'STANDARD' | 'ENTERPRISE'

export interface LicenseLimits {
  max_institutions: number | null
  max_users: number | null
  max_servers: number | null
  features: string[]
}

export interface LicenseStatus {
  activated: boolean
  valid: boolean
  expired: boolean
  expiry_warning: boolean
  is_trial: boolean
  license_id?: string
  edition?: LicenseEdition
  customer?: string
  issued_at?: string
  expires_at?: string
  days_remaining?: number
  limits?: LicenseLimits
  message: string
  upgrade_banner?: { show: boolean; urgency: string; days_remaining: number; message: string }
}

export interface LicenseRecord {
  id: number
  license_id: string
  edition: LicenseEdition
  customer: string
  issued_at: string
  expires_at: string
  is_active: boolean
  is_trial: boolean
  activated_by: string
  activated_at: string
}

export interface LicenseActivateResult {
  message: string
  license_id: string
  edition: LicenseEdition
  customer: string
  expires_at: string
  days_remaining: number
  valid: boolean
  is_trial?: boolean
  license_key?: string
}
