import { fromPromise } from "xstate";

import { getAuthRepository } from "@/data/repositories/auth_repository";
import { Logger } from "@/utils/logger";
import { Result } from "@/utils/result";

import type { BindFacebookIdentityInput } from "../../auth-events";

const log = new Logger("AuthActors");

export const bindFacebookIdentityActor = fromPromise<
  void,
  BindFacebookIdentityInput
>(async ({ input }) => {
  const result = await getAuthRepository().bindFacebookIdentity(input);
  if (Result.isErr(result)) {
    log.warn(
      { err: result.error.message },
      "[auth-machine] bindFacebookIdentityActor failed",
    );
  }
});
