/**
 * Ansible Runner Types
 * Used for remote server provisioning via SSH
 */

export interface AnsibleConfig {
  // Server connection
  serverIp: string
  serverPort?: number
  username?: string
  password: string

  // Domain configuration
  domain: string
  adminEmail?: string

  // Tools to install
  tools: string[]

  // Hub connection (for phone-home)
  hubUrl: string
  registrationToken: string

  // Optional overrides
  orchestratorVersion?: string
  agentVersion?: string
}

export interface AnsibleLogEvent {
  type: 'stdout' | 'stderr' | 'status' | 'progress' | 'error' | 'complete'
  message: string
  step?: string
  progress?: number // 0-100
  timestamp: Date
}

export type AnsibleLogCallback = (event: AnsibleLogEvent) => void | Promise<void>

export interface AnsibleResult {
  success: boolean
  exitCode: number
  duration: number // ms
  logs: AnsibleLogEvent[]
  error?: string
}

export interface ProvisioningStage {
  name: string
  displayName: string
  order: number
}

export const PROVISIONING_STAGES: ProvisioningStage[] = [
  { name: 'connect', displayName: 'Connecting to server', order: 1 },
  { name: 'upload', displayName: 'Uploading setup scripts', order: 2 },
  { name: 'bootstrap', displayName: 'Running bootstrap', order: 3 },
  { name: 'docker', displayName: 'Installing Docker', order: 4 },
  { name: 'orchestrator', displayName: 'Deploying Orchestrator', order: 5 },
  { name: 'agent', displayName: 'Deploying SysAdmin Agent', order: 6 },
  { name: 'tools', displayName: 'Installing tools', order: 7 },
  { name: 'nginx', displayName: 'Configuring Nginx', order: 8 },
  { name: 'register', displayName: 'Registering with Hub', order: 9 },
  { name: 'complete', displayName: 'Provisioning complete', order: 10 },
]
