package userrepository

import (
	"errors"
	userdomain "legalgo-BE-go/internal/domain/user"

	"gorm.io/gorm"
)

func (ur *accessor) GetUserByEmail(email string) (*userdomain.User, error) {
	var user *userdomain.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
}
