package storage

import (
	"encoding/json"

	"helm.sh/helm/v4/pkg/chart/v2/loader"
	"helm.sh/helm/v4/pkg/provenance"
)

func (store *Storage) HelmMeta(filename string) (string, string, error) {
	var err error
	var meta string
	var hash string

	filename = store.makeTmppath(filename)

	chart, err := loader.Load(filename)
	if err != nil {
		return meta, hash, err
	}
	hash, err = provenance.DigestFile(filename)
	if err != nil {
		return meta, hash, err
	}
	metadata, err := json.Marshal(chart.Metadata)
	if err != nil {
		return meta, hash, err
	}
	meta = string(metadata)
	return meta, hash, err
}
