from collections.abc import Sequence from anydi import singleton from email_campaigns.profile.repositories import ProfileRepository from email_campaigns.profile.types import EmailProfile @singleton class ProfileService: def __init__(self, profile_repository: ProfileRepository) -> None: self.profile_repository = profile_repository def find_email_profiles(self, emails: set[str]) -> Sequence[EmailProfile]: profiles = self.profile_repository.find_by_emails(emails) email_to_profile = {profile.email: profile for profile in profiles} result = [] for email in emails: profile = email_to_profile.get(email) result.append( EmailProfile( email=email, profile_id=profile.id if profile else None, first_name=profile.first_name if profile else None, ) ) return result