package service

import (
	"context"

	"oci-portal/internal/oci"
)

// Compartments 递归列出租户下全部 ACTIVE compartment（不含租户根）。
func (s *OciConfigService) Compartments(ctx context.Context, id uint) ([]oci.Compartment, error) {
	cred, err := s.credentialsByID(ctx, id)
	if err != nil {
		return nil, err
	}
	return s.client.ListCompartments(ctx, cred)
}

// credentialsInCompartment 取配置凭据并限定资源操作的目标 compartment（空为租户根）。
func (s *OciConfigService) credentialsInCompartment(ctx context.Context, id uint, compartmentID string) (oci.Credentials, error) {
	cred, err := s.credentialsByID(ctx, id)
	if err != nil {
		return oci.Credentials{}, err
	}
	cred.CompartmentID = compartmentID
	return cred, nil
}
