package userrepository

import (
	"errors"

	authdomain "legalgo-BE-go/internal/domain/auth"

	"gorm.io/gorm"
)

func (ur *UserRepository) GetUserByEmail(email string) (*authdomain.User, error) {
	var user authdomain.User

	if email == "" {
		return nil, errors.New("email is empty")
	}

	if err := ur.DB.First(&user, "email = ?", email).Error; err != nil {
		if errors.Is(err, gorm.ErrRecordNotFound) {
			return nil, errors.New("user not found")
		}
		return nil, err
	}

	return &user, nil
}
