//go:build go1.27

package sqlite3

import (
	
	
	
)

// CreateModule registers a new virtual table module name.
// If create is nil, the virtual table is eponymous.
//
// https://sqlite.org/c3ref/create_module.html
func ( *Conn) [ VTab]( string, ,  VTabConstructor[]) error {
	return CreateModule(, , , )
}

// ExtensionInit loads an SQLite extension library.
//
// https://sqlite.org/loadext.html
func ( *Conn) [ any,  ExtensionLibrary]( func( ) ,  ExtensionInfo) error {
	return ExtensionInit(, , )
}

func ( *Conn) () error {
	const  = DETERMINISTIC | INNOCUOUS
	return errors.Join(
		.CreateFunction("uuid", 0, INNOCUOUS, uuidNew),
		.CreateFunction("uuid", 1, INNOCUOUS, uuidNew),
		.CreateFunction("uuid_str", 1, , uuidStr),
		.CreateFunction("uuid_blob", 1, , uuidBlob))
}

func uuidNew( Context,  ...Value) {
	 := 4
	if len() > 0 {
		 = [0].Int()
	}

	var  uuid.UUID
	switch  {
	case 4:
		 = uuid.NewV4()
	case 7:
		 = uuid.NewV7()
	default:
		.ResultError(fmt.Errorf("uuid: invalid version: %d", )) // notest
		return
	}

	.ResultText(.String())
}

func uuidFrom( Value) ( uuid.UUID,  error) {
	switch  := .Type();  {
	case TEXT:
		 = .UnmarshalText(.RawText())
		if  != nil {
			 = fmt.Errorf("uuid: %w", )
		}

	case BLOB:
		 := .RawBlob()
		if  := len();  != len() {
			 = fmt.Errorf("uuid: invalid BLOB length: %d", )
		} else {
			copy([:], )
		}

	default:
		 = fmt.Errorf("uuid: invalid type: %v", )
	}
	return , 
}

func uuidBlob( Context,  ...Value) {
	,  := uuidFrom([0])
	if  != nil {
		.ResultError() // notest
	} else {
		.ResultBlob([:])
	}
}

func uuidStr( Context,  ...Value) {
	,  := uuidFrom([0])
	if  != nil {
		.ResultError() // notest
	} else {
		.ResultText(.String())
	}
}