import { api } from "./client";

export interface ContentJobSubmitResult {
  jobId: string;
  status: string;
  createdAt: string;
}

export interface ContentJob {
  id: string;
  companyId: string;
  jobType: string;
  status: "queued" | "running" | "done" | "failed";
  input: Record<string, unknown>;
  resultAssetId: string | null;
  errorMessage: string | null;
  sourceTaskId: string | null;
  createdAt: string;
  startedAt: string | null;
  finishedAt: string | null;
}

export function submitContentJob(
  companyId: string,
  jobType: string,
  input: Record<string, unknown>,
  sourceTaskId?: string | null,
): Promise<ContentJobSubmitResult> {
  return api.post<ContentJobSubmitResult>(`/companies/${companyId}/content-jobs`, {
    jobType,
    input,
    sourceTaskId: sourceTaskId ?? null,
  });
}

export function getContentJob(companyId: string, jobId: string): Promise<ContentJob> {
  return api.get<ContentJob>(`/companies/${companyId}/content-jobs/${jobId}`);
}

export function getContentJobAsset(companyId: string, assetId: string): Promise<string> {
  // Returns a URL string to download/view the asset
  return Promise.resolve(`/api/companies/${companyId}/assets/${assetId}`);
}
