import { CreateUserDto, FayidaUserDto } from "@/shared/dto/External-Portal/External-PortalDto";
import {
  registerExternalUser,
  registerFayidaUser,
} from "../services/portalOutgoingService";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { useErrorHandler } from "@/shared/hooks/useErrorHandler";

export const useRegisterExternalPortalUser = () => {
  const [isRegistering, setIsRegistering] = useState(false);
  const [isFayidaRegistering, setIsFayidaRegistering] = useState(false);

   const { t } = useTranslation();
const { handleError } = useErrorHandler(t)
  const registerExternalPortalUser = async (values: CreateUserDto) => {
    try {
      setIsRegistering(true);
      const response = await registerExternalUser(values);
      return { success: true, response };
    } catch (error: any) {
      
      handleError(error)
      setIsRegistering(false);
     
    } finally {
      setIsRegistering(false);
    }
  };
const registerExternalFayidaUser = async (values: FayidaUserDto) => {
  try {
    setIsFayidaRegistering(true);
    const response = await registerFayidaUser(values);
    return { success: true, response };
  } catch (error: any) {
    handleError(error);
  } finally {
    setIsFayidaRegistering(false);
  }
};
  return {
    registerExternalPortalUser,
    registerExternalFayidaUser,
    isRegistering,
    isFayidaRegistering,
  };
};
