// Code generated by pluginator on AnnotationsTransformer; DO NOT EDIT.
package builtin

import (
	"sigs.k8s.io/kustomize/v3/pkg/ifc"
	"sigs.k8s.io/kustomize/v3/pkg/resmap"
	"sigs.k8s.io/kustomize/v3/pkg/transformers"
	"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
	"sigs.k8s.io/yaml"
)

// Add the given annotations to the given field specifications.
type AnnotationsTransformerPlugin struct {
	Annotations map[string]string  `json:"annotations,omitempty" yaml:"annotations,omitempty"`
	FieldSpecs  []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}

func (p *AnnotationsTransformerPlugin) Config(
	ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
	p.Annotations = nil
	p.FieldSpecs = nil
	return yaml.Unmarshal(c, p)
}

func (p *AnnotationsTransformerPlugin) Transform(m resmap.ResMap) error {
	t, err := transformers.NewMapTransformer(
		p.FieldSpecs,
		p.Annotations,
	)
	if err != nil {
		return err
	}
	return t.Transform(m)
}

func NewAnnotationsTransformerPlugin() resmap.TransformerPlugin {
	return &AnnotationsTransformerPlugin{}
}
