import { useMutation } from "@tanstack/react-query";
import { useToast } from "app/components/providers/use-toast";
import api from "app/utils/api";

interface SubscribeToPlanInput {
  subscriptionPlanId: string;
  workspaceId: string;
  planId: string;
}

interface SubscribeToPlanOutput {
  id: string;
  amount: number;
  currency: string;
  payment_link: string;
}

export function useSubscribeToPlan() {
  // Implementation for subscribing to a plan
  const { showError } = useToast();

  return useMutation({
    mutationFn: async (input: SubscribeToPlanInput) => {
      const { data } = await api.post<SubscribeToPlanOutput>("/subscription/purchase", {
        subscription_plan_id: input.subscriptionPlanId,
        workspace_id: input.workspaceId,
        plan_id: input.planId,
      });
      return data;
    }
  });
}
