package userrepository

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

func (ur *accessor) GetUserProfile(email string) (*userdomain.UserProfile, 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
	}

	userProfile := &userdomain.UserProfile{
		ID:        user.ID,
		Email:     user.Email,
		Phone:     user.Phone,
		Subscribe: user.Subscribe,
	}

	return userProfile, nil
}
