package accountdb

import (
	"github.com/tidbcloud/account/idl/pbgen/proto/account"
	"github.com/tidbcloud/account/idl/pbgen/proto/acl"
	"github.com/tidbcloud/dataflow-service-ng/pkg/account/accounttypes"
)

type User struct {
	accounttypes.User
	Role           acl.OrgRole
	TenantID       uint64
	IsImpersonated bool
}

func ConvertAuthUserToUser(authUser *account.GetAuthUserResponse) *User {
	user := ConvertUser(authUser.User)
	org := convertOrg(authUser.Org)
	user.Tenant = org
	user.TenantID = org.ID

	result := &User{
		User:           *user,
		Role:           authUser.OrgRole,
		TenantID:       org.ID,
		IsImpersonated: authUser.IsImpersonated,
	}
	return result
}
