package watch_graph //nolint:staticcheck

import (
	corev1 "k8s.io/api/core/v1"
)

func (vx *wgObject2vertex) collectVolumeV1Arcs(v *corev1.Volume, arcType ArcType) {
	// Only a single field is set.
	switch {
	case v.PersistentVolumeClaim != nil:
		vx.setArcToGVK(persistentVolumeClaimGVK, v.PersistentVolumeClaim.ClaimName, ArcAttrs{}, arcType)
	case v.Secret != nil:
		vx.setArcToSecret(v.Secret.SecretName, ArcAttrs{}, arcType)
	case v.ConfigMap != nil:
		vx.setArcToConfigMap(v.ConfigMap.Name, ArcAttrs{}, arcType)
	case v.Projected != nil:
		collectEach(v.Projected.Sources, arcType, vx.collectVolumeProjectionV1Arcs)
	case v.CSI != nil:
		if v.CSI.NodePublishSecretRef != nil {
			vx.setArcToSecret(v.CSI.NodePublishSecretRef.Name, ArcAttrs{}, arcType)
		}
	case v.Ephemeral != nil:
		vx.collectPersistentVolumeClaimSpecV1Arcs(&v.Ephemeral.VolumeClaimTemplate.Spec, arcType)
	}
}

func (vx *wgObject2vertex) collectVolumeProjectionV1Arcs(p *corev1.VolumeProjection, arcType ArcType) {
	switch {
	case p.Secret != nil:
		vx.setArcToSecret(p.Secret.Name, ArcAttrs{}, arcType)
	case p.ConfigMap != nil:
		vx.setArcToConfigMap(p.ConfigMap.Name, ArcAttrs{}, arcType)
	case p.ClusterTrustBundle != nil:
		if p.ClusterTrustBundle.Name != nil {
			vx.setArcToGVK(clusterTrustBundleV1Alpha1GVK, *p.ClusterTrustBundle.Name, ArcAttrs{}, arcType)
		}
	}
}
