package httpsfv

import (
	
)

// Item is a bare value and associated parameters.
// See https://httpwg.org/specs/rfc9651.html#item.
type Item struct {
	Value  interface{}
	Params *Params
}

// NewItem returns a new Item.
func ( interface{}) Item {
	assertBareItem()

	return Item{, NewParams()}
}

func ( Item) () {
}

// marshalSFV serializes as defined in
// https://httpwg.org/specs/rfc9651.html#ser-item.
func ( Item) ( *strings.Builder) error {
	if .Value == nil {
		return ErrInvalidBareItem
	}

	if  := marshalBareItem(, .Value);  != nil {
		return 
	}

	return .Params.marshalSFV()
}

// UnmarshalItem parses an item as defined in
// https://httpwg.org/specs/rfc9651.html#parse-item.
func ( []string) (Item, error) {
	 := &scanner{
		data: strings.Join(, ","),
	}

	.scanWhileSp()

	,  := parseItem()
	if  != nil {
		return Item{}, 
	}

	.scanWhileSp()

	if !.eof() {
		return Item{}, &UnmarshalError{off: .off}
	}

	return , nil
}

func parseItem( *scanner) (Item, error) {
	,  := parseBareItem()
	if  != nil {
		return Item{}, 
	}

	,  := parseParams()
	if  != nil {
		return Item{}, 
	}

	return Item{, }, nil
}