import uuid

from sqlalchemy.orm import Session

from app.models.customer_profile import CustomerProfile


def get_or_create_profile(db: Session, customer_id: uuid.UUID) -> CustomerProfile:
    """Lazily creates an empty profile row on first read/update — a
    customer who never touches profile completion never gets one,
    same reasoning as app.services.dispatch.get_or_create_profile for
    couriers."""
    profile = (
        db.query(CustomerProfile).filter(CustomerProfile.user_id == customer_id).first()
    )
    if profile is None:
        profile = CustomerProfile(user_id=customer_id)
        db.add(profile)
        db.commit()
        db.refresh(profile)
    return profile
