package api

import (
	"encoding/base64"
	"time"
)

// InstanceNVRAMVariablePut represents the modifiable fields of a UEFI variable.
//
// swagger:model
//
// API extension: instance_nvram.
type InstanceNVRAMVariablePut struct {
	// Dissected data.
	Data any `json:"data,omitempty"`

	// Variable attributes.
	Attributes []string `json:"attributes"`

	// Authenticated variable timestamp.
	Timestamp *time.Time `json:"timestamp,omitempty"`
}

// InstanceNVRAMVariable represents a UEFI variable.
//
// swagger:model
//
// API extension: instance_nvram.
type InstanceNVRAMVariable struct {
	InstanceNVRAMVariablePut

	// Binary data.
	Binary []byte `json:"binary"`
}

// MarshalYAML marshals binary variable data to base64.
func (v *InstanceNVRAMVariable) MarshalYAML() (any, error) {
	return struct {
		Binary     string     `yaml:"binary,omitempty"`
		Data       any        `yaml:"data,omitempty"`
		Attributes []string   `yaml:"attributes"`
		Timestamp  *time.Time `yaml:"timestamp,omitempty"`
	}{
		Binary:     base64.StdEncoding.EncodeToString(v.Binary),
		Data:       v.Data,
		Attributes: v.Attributes,
		Timestamp:  v.Timestamp,
	}, nil
}
