export type JobStatus = "queued" | "running" | "succeeded" | "failed";

export type Job = {
  id: string;
  type: string;
  payload: Record<string, unknown>;
  status: JobStatus;
  priority: number;
  available_at: string;
  attempts: number;
  max_attempts: number;
  idempotency_key: string | null;
  locked_by: string | null;
  locked_until: string | null;
  last_error: string;
  result: unknown;
  created_at: string;
  updated_at: string;
  finished_at: string | null;
};

export type JobEvent = {
  id: number;
  job: string;
  type: string;
  attempt: number;
  worker_id: string | null;
  message: string;
  data: Record<string, unknown>;
  created_at: string;
};

export type CursorPage<T> = {
  next: string | null;
  previous: string | null;
  results: T[];
};

export type LimitOffsetPage<T> = {
  count: number;
  next: string | null;
  previous: string | null;
  results: T[];
};

export type JobStats = {
  total: number;
  by_status: Record<JobStatus, number>;
  overdue_running: number;
  retries_pending: number;
  oldest_queued_at: string | null;
};

export type Health = {
  ok: boolean;
  database: string;
  detail?: string;
};
