package resdiskloop

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, "loop")

	kwFile = keywords.Keyword{
		Attr:     "File",
		Example:  "/srv/{fqdn}-loop-{rindex}",
		Option:   "file",
		Required: true,
		Scopable: true,
		Text:     keywords.NewText(fs, "text/kw/file"),
	}
	kwSize = keywords.Keyword{
		Attr:         "Size",
		Example:      "100m",
		Option:       "size",
		Provisioning: true,
		Scopable:     true,
		Text:         keywords.NewText(fs, "text/kw/size"),
	}
)

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.AddKeywords(resdisk.BaseKeywords...)
	m.AddKeywords(
		&kwFile,
		&kwSize,
	)
	return m
}
