package kubernetesmetav2

import (
	"time"

	storage "k8s.io/api/storage/v1" //nolint:typecheck

	"github.com/alibaba/ilogtail/pkg/helper/k8smeta"
	"github.com/alibaba/ilogtail/pkg/models"
)

func (m *metaCollector) processStorageClassEntity(data *k8smeta.ObjectWrapper, method string) []models.PipelineEvent {
	if obj, ok := data.Raw.(*storage.StorageClass); ok {
		log := &models.Log{}
		log.Contents = models.NewLogContents()
		log.Timestamp = uint64(time.Now().Unix())
		m.processEntityCommonPart(log.Contents, obj.Kind, obj.Namespace, obj.Name, method, data.FirstObservedTime, data.LastObservedTime, obj.CreationTimestamp)

		// custom fields
		log.Contents.Add("api_version", obj.APIVersion)
		if m.serviceK8sMeta.EnableLabels {
			log.Contents.Add("labels", m.processEntityJSONObject(obj.Labels))
		}
		if m.serviceK8sMeta.EnableAnnotations {
			log.Contents.Add("annotations", m.processEntityJSONObject(obj.Annotations))
		}
		if obj.ReclaimPolicy != nil {
			log.Contents.Add("reclaim_policy", string(*obj.ReclaimPolicy))
		} else {
			log.Contents.Add("reclaim_policy", "")
		}
		if obj.VolumeBindingMode != nil {
			log.Contents.Add("volume_binding_mode", string(*obj.VolumeBindingMode))
		} else {
			log.Contents.Add("volume_binding_mode", "")
		}
		return []models.PipelineEvent{log}
	}
	return nil
}
