package admin

import (
	"github.com/pingcap/errcode"
	"github.com/pingcap/errors"
)

type CentralUserProfile struct {
	Id    uint64
	Name  string
	Email string
	Roles []string
}

func (m UserContext) GetCentralUserProfile() (*CentralUserProfile, error) {
	if m.tenantAndUser.ID == 0 {
		return nil, errcode.NewInvalidInputErr(errors.New("not a normal user"))
	}
	var roles []string
	for _, item := range m.tenantAndUser.Roles {
		roles = append(roles, item.Name)
	}
	return &CentralUserProfile{
		Id:    m.tenantAndUser.ID.Uint64(),
		Name:  m.tenantAndUser.LastName,
		Email: m.tenantAndUser.Email,
		Roles: roles,
	}, nil
}
