/**
 * CI/CD 流水线相关类型定义
 */

// ==================== 构建相关 ====================

/** 构建状态 */
export type BuildStatus = 'pending' | 'running' | 'success' | 'failed' | 'cancelled'

/** 构建触发方式 */
export type BuildTrigger = 'manual' | 'push' | 'schedule' | 'api'

/** 构建任务 */
export interface Build {
  id?: number
  websiteId?: number
  buildNo?: string
  branch?: string
  commitId?: string
  commitMessage?: string
  author?: string
  trigger?: BuildTrigger
  status?: BuildStatus
  duration?: number
  logs?: string
  artifacts?: BuildArtifact[]
  startTime?: string
  endTime?: string
  createTime?: string
}

/** 构建产物 */
export interface BuildArtifact {
  name?: string
  path?: string
  size?: number
  downloadUrl?: string
}

/** 构建搜索参数 */
export interface BuildParam {
  page?: number
  limit?: number
  websiteId?: number
  branch?: string
  status?: BuildStatus
  trigger?: BuildTrigger
  timeStart?: string
  timeEnd?: string
}

// ==================== 部署相关 ====================

/** 部署状态 */
export type DeployStatus = 'pending' | 'deploying' | 'success' | 'failed' | 'rollback'

/** 部署环境 */
export type DeployEnv = 'development' | 'staging' | 'production'

/** 部署记录 */
export interface Deploy {
  id?: number
  websiteId?: number
  buildId?: number
  buildNo?: string
  version?: string
  env?: DeployEnv
  status?: DeployStatus
  previousVersion?: string
  rollbackFrom?: string
  deployer?: string
  duration?: number
  startTime?: string
  endTime?: string
  createTime?: string
}

/** 部署搜索参数 */
export interface DeployParam {
  page?: number
  limit?: number
  websiteId?: number
  env?: DeployEnv
  status?: DeployStatus
  timeStart?: string
  timeEnd?: string
}

// ==================== 流水线配置相关 ====================

/** 流水线配置 */
export interface PipelineConfig {
  id?: number
  websiteId?: number
  name?: string
  enabled?: boolean
  autoDeploy?: boolean
  branchRules?: BranchRule[]
  environmentVars?: EnvVar[]
  webhooks?: Webhook[]
  createTime?: string
  updateTime?: string
}

/** 分支规则 */
export interface BranchRule {
  branch?: string
  autoBuild?: boolean
  autoDeploy?: boolean
  deployEnv?: DeployEnv
  requireApproval?: boolean
}

/** 环境变量 */
export interface EnvVar {
  key?: string
  value?: string
  isSecret?: boolean
}

/** Webhook 配置 */
export interface Webhook {
  id?: number
  url?: string
  secret?: string
  events?: string[]
  enabled?: boolean
}

// ==================== 运行时相关 ====================

/** 运行时实例 */
export interface RuntimeInstance {
  id?: number
  websiteId?: number
  env?: DeployEnv
  status?: 'running' | 'stopped' | 'restarting' | 'error'
  version?: string
  instances?: number
  cpu?: number
  memory?: number
  region?: string
  startTime?: string
  createTime?: string
}
