package staffrepository

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

func (a *accessor) GetUsers() ([]userdomain.UserProfile, error) {
	var usersRaw []userdomain.User
	if err := a.db.
		Preload("Subscribe").
		Preload("Subscribe.SubscribePlan").
		Find(&usersRaw).
		Error; err != nil {
		return nil, err
	}

	users := []userdomain.UserProfile{}

	for _, user := range usersRaw {
		users = append(users, userdomain.UserProfile{
			ID:        user.ID,
			Email:     user.Email,
			Phone:     user.Phone,
			Subscribe: user.Subscribe,
			CreatedAt: user.CreatedAt,
		})
	}

	return users, nil
}
