package service

import (
	"context"

	"github.com/tidbcloud/core-portal/pkg/auth"
)

type openAPIService struct {
}

type OpenAPIService interface {
	CurrentUser(context.Context) *auth.User
}

func New() OpenAPIService {
	return &openAPIService{}
}

func (s *openAPIService) CurrentUser(ctx context.Context) *auth.User {
	u, err := auth.GetUserFromContext(ctx)
	if err != nil {
		panic("expected user claim")
	}
	return u
}
