// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package omni

import (
	"github.com/cosi-project/runtime/pkg/resource"
	"github.com/cosi-project/runtime/pkg/resource/meta"
	"github.com/cosi-project/runtime/pkg/resource/protobuf"
	"github.com/cosi-project/runtime/pkg/resource/typed"

	"github.com/siderolabs/omni/client/api/omni/specs"
	"github.com/siderolabs/omni/client/pkg/omni/resources"
)

// NewInstallationMedia creates new InstallationMedia state.
func NewInstallationMedia(filename string) *InstallationMedia {
	return typed.NewResource[InstallationMediaSpec, InstallationMediaExtension](
		resource.NewMetadata(resources.EphemeralNamespace, InstallationMediaType, filename, resource.VersionUndefined),
		protobuf.NewResourceSpec(&specs.InstallationMediaSpec{}),
	)
}

const (
	// InstallationMediaType is the type of InstallationMedia resource.
	//
	// tsgen:InstallationMediaType
	InstallationMediaType = resource.Type("InstallationMedias.omni.sidero.dev")
)

// InstallationMedia resource describes a Talos installation media that can be generated by the image factory. It also describes the necessary parameters to be passed to the image factory.
//
// InstallationMedia resource ID is a human-readable string without white-space that uniquely identifies the installation media.
type InstallationMedia = typed.Resource[InstallationMediaSpec, InstallationMediaExtension]

// InstallationMediaSpec wraps specs.InstallationMediaSpec.
type InstallationMediaSpec = protobuf.ResourceSpec[specs.InstallationMediaSpec, *specs.InstallationMediaSpec]

// InstallationMediaExtension providers auxiliary methods for InstallationMedia resource.
type InstallationMediaExtension struct{}

// ResourceDefinition implements [typed.Extension] interface.
func (InstallationMediaExtension) ResourceDefinition() meta.ResourceDefinitionSpec {
	return meta.ResourceDefinitionSpec{
		Type:             InstallationMediaType,
		Aliases:          []resource.Type{},
		DefaultNamespace: resources.EphemeralNamespace,
		PrintColumns:     []meta.PrintColumn{},
	}
}
