# VM Lifecycle Contracts
#
# Type definitions for VM persistence and lifecycle management
# Migrated from provisioning/kcl/vm_lifecycle.k

{
  VmPersistence = {
    mode | [| 'permanent, 'temporary |] | default = 'permanent,
    auto_start | Bool | default = false,
    restart_policy | [| 'no, 'always, 'on_failure |] | default = 'always,
    max_retries | Number | default = 5,
    ttl_hours | Number | default = 24,
    auto_cleanup | Bool | default = true,
    force_cleanup | Bool | default = false,
    cleanup_grace_period | Number | default = 60,
    created_at_unix | Number,
    scheduled_cleanup | Number | optional,
    last_state_change | Number | optional,
  },

  VmLifecyclePolicy = {
    on_host_reboot | [| 'start, 'keep_stopped, 'destroy |] | default = 'start,
    on_host_shutdown | [| 'shutdown, 'save_state, 'destroy |] | default = 'shutdown,
    on_memory_pressure | [| 'suspend, 'kill, 'none |] | default = 'none,
    on_disk_full | [| 'suspend, 'kill, 'none |] | default = 'none,
    enforce_memory_limit | Bool | default = true,
    enforce_cpu_limit | Bool | default = true,
    enforce_disk_limit | Bool | default = false,
  },

  VmCleanupSchedule = {
    vm_name | String,
    vm_id | String,
    mode | [| 'temporary |] | default = 'temporary,
    created_at | String,
    scheduled_cleanup_at | String,
    ttl_hours | Number,
    cleanup_status | [| 'pending, 'in_progress, 'completed, 'failed |] | default = 'pending,
    cleanup_attempts | Number | default = 0,
    last_cleanup_attempt | String | optional,
    cleanup_error | String | optional,
  },

  VmRecoveryState = {
    vm_name | String,
    vm_id | String,
    state_before_shutdown | [| 'running, 'stopped, 'paused |],
    creation_timestamp | String,
    last_checkpoint | String,
    memory_snapshot | String | optional,
    memory_size_mb | Number | optional,
    config_snapshot | Dyn,
  },

  VmAutoStartConfig = {
    vm_name | String,
    enabled | Bool | default = true,
    start_order | Number | default = 0,
    start_delay_seconds | Number | default = 0,
    wait_for_ssh | Bool | default = true,
    ssh_timeout_seconds | Number | default = 300,
    on_start_failure | [| 'stop, 'retry, 'ignore |] | default = 'retry,
    max_start_retries | Number | default = 3,
    depends_on | Array String | default = [],
  },

  VmCleanupPolicy = {
    cleanup_enabled | Bool | default = true,
    check_interval_minutes | Number | default = 60,
    cleanup_window_start | String | default = "02:00",
    cleanup_window_end | String | default = "06:00",
    cleanup_in_window_only | Bool | default = true,
    max_concurrent_cleanups | Number | default = 3,
    cleanup_batch_size | Number | default = 10,
    require_confirmation | Bool | default = false,
    dry_run_mode | Bool | default = false,
    skip_on_low_resources | Bool | default = true,
    log_cleanup_operations | Bool | default = true,
    alert_on_cleanup_failure | Bool | default = true,
    retention_days | Number | default = 7,
  },

  VmStateSnapshot = {
    vm_name | String,
    snapshot_time | String,
    vm_state | [| 'stopped, 'starting, 'running, 'stopping, 'paused, 'error |],
    cpu_usage_percent | Number,
    memory_usage_mb | Number,
    disk_usage_gb | Number,
    ip_addresses | Array String,
    mac_addresses | Array String,
    uptime_seconds | Number,
    restart_count | Number,
  },
}
