from pathlib import Path
import logging
import sys

from dotenv import load_dotenv

PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
    sys.path.insert(0, str(PROJECT_ROOT))

from app.face_matcher import FaceMatcher
from models.user_model import initialize_database


def main():
    load_dotenv()
    logging.basicConfig(
        level="INFO",
        format="%(asctime)s %(levelname)s %(name)s: %(message)s",
    )
    initialize_database()
    matcher = FaceMatcher()
    delivery_summary = matcher.send_grouped_matches()

    if not delivery_summary:
        print("No new matches found for delivery.")
        return

    print("Emails sent successfully:")
    for email, image_urls in delivery_summary.items():
        print(f"- {email}")
        for image_url in image_urls:
            print(f"  {image_url}")


if __name__ == "__main__":
    main()
