package userrepository

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

func (ur *accessor) GetUserProfile(id string) (*userdomain.UserProfile, error) {
	var user *userdomain.User

	if id == "" {
		return nil, fmt.Errorf("email is empty")
	}

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

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

	return userProfile, nil
}
