import type { ClaudeJobStatus } from '@prisma/client'

const JOB_DB_TO_API = {
  QUEUED: 'queued',
  CLAIMED: 'claimed',
  RUNNING: 'running',
  DONE: 'done',
  FAILED: 'failed',
  CANCELLED: 'cancelled',
  SKIPPED: 'skipped',
} as const satisfies Record<ClaudeJobStatus, string>

const JOB_API_TO_DB: Record<string, ClaudeJobStatus> = {
  queued: 'QUEUED',
  claimed: 'CLAIMED',
  running: 'RUNNING',
  done: 'DONE',
  failed: 'FAILED',
  cancelled: 'CANCELLED',
  skipped: 'SKIPPED',
}

export type ClaudeJobStatusApi = typeof JOB_DB_TO_API[ClaudeJobStatus]

export function jobStatusToApi(s: ClaudeJobStatus): ClaudeJobStatusApi {
  return JOB_DB_TO_API[s]
}

export function jobStatusFromApi(s: string): ClaudeJobStatus | null {
  return JOB_API_TO_DB[s.toLowerCase()] ?? null
}

export const JOB_STATUS_API_VALUES = Object.values(JOB_DB_TO_API)
export const ACTIVE_JOB_STATUSES: ClaudeJobStatus[] = ['QUEUED', 'CLAIMED', 'RUNNING']
