// SPDX-License-Identifier: MIT
// Copyright (c) 2025-2026 SenWeaverCoding
// Licensed under the MIT License.



import type { CodingModeId } from './codingMode'
import type { PermissionMode } from './settings'

export type TaskNotificationConfig = {
  enabled: boolean
  channels: ('telegram' | 'feishu')[]
}

export type TaskTriggerType = 'cron' | 'interval' | 'once' | 'idle' | 'session_end'

export type TaskPriority = 'low' | 'normal' | 'high'

export type CronTask = {
  id: string
  name: string
  description?: string
  cron: string
  prompt: string
  enabled: boolean
  recurring?: boolean
  permanent?: boolean
  createdAt: number
  lastRunAt?: number
  lastFiredAt?: string
  nextRunAt?: number
  permissionMode?: PermissionMode | string
  codingMode?: CodingModeId | string
  model?: string
  folderPath?: string
  useWorktree?: boolean
  notification?: TaskNotificationConfig
  triggerType?: TaskTriggerType
  everyMs?: number
  runAt?: string
  afterIdleMs?: number
  maxDurationMs?: number
  requireIdleMs?: number
  priority?: TaskPriority
  allowedTools?: string[]
}

export type CreateTaskInput = {
  name: string
  description?: string
  cron?: string
  prompt: string
  enabled?: boolean
  recurring?: boolean
  permanent?: boolean
  permissionMode?: PermissionMode | string
  codingMode?: CodingModeId | string
  model?: string
  folderPath?: string
  useWorktree?: boolean
  notification?: TaskNotificationConfig
  triggerType?: TaskTriggerType
  everyMs?: number
  runAt?: string
  afterIdleMs?: number
  maxDurationMs?: number
  requireIdleMs?: number
  priority?: TaskPriority
  allowedTools?: string[]
}

export type TaskRun = {
  id: string
  taskId: string
  taskName: string
  startedAt: string
  completedAt?: string
  status: 'running' | 'completed' | 'failed' | 'timeout'
  prompt: string
  output?: string
  error?: string
  exitCode?: number
  durationMs?: number
  sessionId?: string
}
