//go:build linux

package resdiskcrypt

import (
	"embed"

	"github.com/opensvc/om3/v3/core/driver"
	"github.com/opensvc/om3/v3/core/keywords"
	"github.com/opensvc/om3/v3/core/manifest"
	"github.com/opensvc/om3/v3/core/naming"
	"github.com/opensvc/om3/v3/drivers/resdisk"
)

var (
	//go:embed text
	fs embed.FS

	drvID = driver.NewID(driver.GroupDisk, "crypt")

	kws = []*keywords.Keyword{
		{
			Attr:        "Name",
			DefaultText: keywords.NewText(fs, "text/kw/name.default"),
			Example:     "{fqdn}-crypt",
			Option:      "name",
			Scopable:    true,
			Text:        keywords.NewText(fs, "text/kw/name"),
		},
		{
			Attr:     "Dev",
			Example:  "/dev/{fqdn}/lv1",
			Option:   "dev",
			Required: true,
			Scopable: true,
			Text:     keywords.NewText(fs, "text/kw/dev"),
		},
		{
			Attr:         "ManagePassphrase",
			Converter:    "bool",
			Default:      "true",
			Option:       "manage_passphrase",
			Provisioning: true,
			Scopable:     true,
			Text:         keywords.NewText(fs, "text/kw/manage_passphrase"),
		},
		{
			Attr:     "Secret",
			Default:  "{name}",
			Option:   "secret",
			Scopable: true,
			Text:     keywords.NewText(fs, "text/kw/secret"),
		},
		{
			Attr:         "FormatLabel",
			Default:      "{fqdn}",
			Option:       "label",
			Provisioning: true,
			Scopable:     true,
			Text:         keywords.NewText(fs, "text/kw/label"),
		},
	}
)

func init() {
	driver.Register(drvID, New)
}

func (t *T) DriverID() driver.ID {
	return drvID
}

// Manifest exposes to the core the input expected by the driver.
func (t *T) Manifest() *manifest.T {
	m := manifest.New(drvID, t)
	m.Kinds.Or(naming.KindSvc, naming.KindVol)
	m.Add(manifest.ContextObjectPath)
	m.AddKeywords(resdisk.BaseKeywords...)
	m.AddKeywords(kws...)
	return m
}
