package cluster

import (
	"context"

	"github.com/pingcap/dbaas/central/db/entity"
	"github.com/tidbcloud/idl/pbgen/proto/central"
)

func (s *clusterService) GetDataIngestionProfile(c context.Context, req *central.ClusterIdReq) (*central.DataIngestionProfile, error) {
	orgID := entity.ID(req.OrgId)
	projectID := entity.ID(req.ProjectId)
	userContext := s.userCluster(c)
	err := userContext.CheckOrgIDAndProjectID(orgID, projectID)
	if err != nil {
		return nil, err
	}

	profile, err := s.userCluster(c).GetDataIngestionProfile(c, entity.ID(req.ClusterId))
	if err != nil {
		return nil, err
	}
	return &central.DataIngestionProfile{
		Type:          profile.Type,
		AwsExternalId: profile.AwsExternalId,
		AwsAccountId:  profile.AwsAccountId,
		GcpAccountId:  profile.GcpAccountId,
	}, nil
}
