import type { Command } from '../commands.js'
import type { LocalCommandCall } from '../types/command.js'
import { formatCodexUsage, getCodexUsage } from '../services/oauth/codexRateLimits.js'

const call: LocalCommandCall = async () => {
  const snap = getCodexUsage()
  return { type: 'text', value: formatCodexUsage(snap) }
}

const codexUsage = {
  type: 'local',
  name: 'codex-usage',
  description: 'Show current ChatGPT Codex usage / rate-limit window',
  argumentHint: '',
  isEnabled: () => true,
  isHidden: false,
  supportsNonInteractive: true,
  load: () => Promise.resolve({ call }),
} satisfies Command

export default codexUsage
