package userrepository

import (
	"errors"

	userdomain "legalgo-BE-go/internal/domain/user"
)

func (ur *UserRepository) GetUserByID(email string) (*userdomain.User, error) {
	var user userdomain.User

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

	if err := ur.DB.
		Preload("Subscribe").
		Preload("Subscribe.SubscribePlan").
		First(&user, "email = ?", email).Error; err != nil {
		return nil, err
	}

	return &user, nil
}
