// TODO: Move externally tagged JSON union helpers to a separate
// go.pact.im/x/jsonunion module.

package config

import (
	
	
	

	
)

// readExternalTag consumes the beginning of an externally tagged JSON union.
//
// For null and empty-object values, readExternalTag consumes the entire value
// and returns an empty option. For a non-empty object, it consumes the object
// start and returns the provider name token. The decoder is left positioned
// at the provider value, which the caller must decode before calling
// [readExternalTagEnd].
func ( *jsontext.Decoder) (option.Of[jsontext.Token], error) {
	switch  := .PeekKind();  {
	case jsontext.KindBeginObject:
	case jsontext.KindNull:
		if ,  := .ReadToken();  != nil {
			return option.Nil[jsontext.Token](), 
		}
		return option.Nil[jsontext.Token](), nil
	default:
		return option.Nil[jsontext.Token](), fmt.Errorf("unexpected token %s", )
	}

	if ,  := .ReadToken();  != nil {
		return option.Nil[jsontext.Token](), 
	}
	if .PeekKind() == jsontext.KindEndObject {
		if ,  := .ReadToken();  != nil {
			return option.Nil[jsontext.Token](), 
		}
		return option.Nil[jsontext.Token](), nil
	}

	,  := .ReadToken()
	if  != nil {
		return option.Nil[jsontext.Token](), 
	}
	if  := .Kind();  != jsontext.KindString {
		return option.Nil[jsontext.Token](), fmt.Errorf("tag must be a string, got %s", )
	}
	return option.Value(), nil
}

// readExternalTagEnd consumes the end of an externally tagged JSON union.
//
// The decoder must be positioned after the provider value. readExternalTagEnd
// rejects objects with more than one provider.
func ( *jsontext.Decoder) error {
	if  := .PeekKind();  != jsontext.KindEndObject {
		return errors.New("must contain exactly one tag")
	}
	,  := .ReadToken()
	return 
}