/**
 * SSO 单点登录相关类型定义
 */

/** SSO 提供商类型 */
export type SSOProvider = 'oidc' | 'saml' | 'cas' | 'ldap' | 'oauth2'

/** SSO 同步方向 */
export type SyncDirection = 'oneway' | 'twoway'

/** SSO 状态 */
export type SSOStatus = 'inactive' | 'active' | 'error'

/**
 * SSO 配置
 */
export interface SSOConfig {
  id?: number
  enterpriseId?: number
  provider?: SSOProvider
  name?: string
  enabled?: boolean
  status?: SSOStatus
  // OIDC 配置
  issuer?: string
  clientId?: string
  clientSecret?: string
  authorizationUrl?: string
  tokenUrl?: string
  userInfoUrl?: string
  scopes?: string[]
  // SAML 配置
  idpEntityId?: string
  idpSsoUrl?: string
  idpCertificate?: string
  spEntityId?: string
  spAcsUrl?: string
  // 通用配置
  syncUsers?: boolean
  syncDirection?: SyncDirection
  autoCreateUsers?: boolean
  defaultRole?: string
  attributeMapping?: Record<string, string>
  logo?: string
  lastSyncTime?: string
  errorMessage?: string
  createTime?: string
  updateTime?: string
}

/**
 * SSO 用户会话
 */
export interface SSOSession {
  id?: number
  userId?: number
  username?: string
  provider?: SSOProvider
  loginTime?: string
  ip?: string
  userAgent?: string
}

/**
 * SSO 日志
 */
export interface SSOLog {
  id?: number
  type?: 'login' | 'logout' | 'error' | 'sync'
  provider?: SSOProvider
  userId?: number
  username?: string
  ip?: string
  status?: 'success' | 'failed'
  message?: string
  createTime?: string
}
