import { useConvexMutation } from '@/app/hooks/use-convex-mutation';
import { useConvexQuery } from '@/app/hooks/use-convex-query';
import { api } from '@/convex/_generated/api';
import type { Id } from '@/convex/_generated/dataModel';

export function useExecutionStatus(
  executionId: Id<'wfExecutions'> | undefined,
) {
  return useConvexQuery(
    api.wf_executions.queries.getExecutionStatus,
    executionId ? { executionId } : 'skip',
  );
}

export function useWorkflowHumanInputApproval(approvalId: string | undefined) {
  return useConvexQuery(
    api.approvals.queries.getApproval,
    approvalId
      ? // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- approval ID string from execution.waitingFor
        { approvalId: approvalId as Id<'approvals'> }
      : 'skip',
  );
}

export function useCancelExecution() {
  return useConvexMutation(api.wf_executions.mutations.cancelExecution);
}
