'use client';

import { useMutation } from '@tanstack/react-query';

import {
  commitBootstrapCsvStep,
  commitConfiguredBootstrapCsv,
  commitConfiguredSetupCsvFiles,
  commitSetupCsvFiles,
  previewBootstrapCsvStep,
  previewConfiguredBootstrapCsv,
  previewConfiguredSetupCsvFiles,
  previewSetupCsvFiles
} from './service';

export function useCsvPreview() {
  return useMutation({
    mutationFn: (files: File[]) => previewSetupCsvFiles(files)
  });
}

export function useCsvCommit() {
  return useMutation({
    mutationFn: (input: { files: File[]; previewHash: string; dryRun?: boolean }) => commitSetupCsvFiles(input)
  });
}

export function useConfiguredCsvPreview() {
  return useMutation({
    mutationFn: () => previewConfiguredSetupCsvFiles()
  });
}

export function useConfiguredCsvCommit() {
  return useMutation({
    mutationFn: (input: { previewHash: string; dryRun?: boolean }) => commitConfiguredSetupCsvFiles(input)
  });
}

export function useBootstrapCsvPreview() {
  return useMutation({
    mutationFn: (input: { stepKey: string; file: File; bootstrapToken?: string }) => previewBootstrapCsvStep(input)
  });
}

export function useBootstrapCsvCommit() {
  return useMutation({
    mutationFn: (input: {
      stepKey: string;
      file: File;
      previewHash: string;
      dryRun?: boolean;
      bootstrapToken?: string;
    }) => commitBootstrapCsvStep(input)
  });
}

export function useConfiguredBootstrapCsvPreview() {
  return useMutation({
    mutationFn: (input: { bootstrapToken?: string }) => previewConfiguredBootstrapCsv(input)
  });
}

export function useConfiguredBootstrapCsvCommit() {
  return useMutation({
    mutationFn: (input: { previewHash: string; dryRun?: boolean; bootstrapToken?: string }) =>
      commitConfiguredBootstrapCsv(input)
  });
}
