import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useParams } from 'react-router-dom';

import { ReposService } from '@/client/services/ReposService';

export function useArchiveRepo() {
  const { workspaceName = '', repoName = '' } = useParams();
  const qc = useQueryClient();

  const archive = useMutation({
    mutationFn: () => ReposService.repoArchive({ workspaceName, repoName }),
    onSuccess: () => {
      qc.invalidateQueries({ queryKey: ['repo', workspaceName, repoName] });
    },
  });

  const unarchive = useMutation({
    mutationFn: () => ReposService.repoUnarchive({ workspaceName, repoName }),
    onSuccess: () => {
      qc.invalidateQueries({ queryKey: ['repo', workspaceName, repoName] });
    },
  });

  return { archive, unarchive };
}
