import { IAdapter, RepositoryBuilder } from "@/contexts/common/domain";
import { Email } from "@shared/contexts";
import { AuthUser } from "../domain";
import { IAuthRepository } from "../domain/repository";

export const findUserByEmail = async (
  email: Email,
  adapter: IAdapter,
  repository: RepositoryBuilder<IAuthRepository>
): Promise<AuthUser | null> => {
  return await adapter
    .startTransaction()
    .complete(async (t) => repository({ transaction: t }).findUserByEmail(email));
};
