package pgx

import (
	

	
	
	
)

// PostgreSQL format codes
const (
	TextFormatCode   = 0
	BinaryFormatCode = 1
)

func convertSimpleArgument( *pgtype.Map,  any) (any, error) {
	if anynil.Is() {
		return nil, nil
	}

	,  := .Encode(0, TextFormatCode, , []byte{})
	if  != nil {
		return nil, 
	}
	if  == nil {
		return nil, nil
	}
	return string(), nil
}

func encodeCopyValue( *pgtype.Map,  []byte,  uint32,  any) ([]byte, error) {
	if anynil.Is() {
		return pgio.AppendInt32(, -1), nil
	}

	 := len()
	 = pgio.AppendInt32(, -1)
	,  := .Encode(, BinaryFormatCode, , )
	if  != nil {
		if ,  := tryScanStringCopyValueThenEncode(, , , );  == nil {
			 = 
		} else {
			return nil, 
		}
	}

	if  != nil {
		 = 
		pgio.SetInt32([:], int32(len([:])-4))
	}
	return , nil
}

func tryScanStringCopyValueThenEncode( *pgtype.Map,  []byte,  uint32,  any) ([]byte, error) {
	,  := .(string)
	if ! {
		return nil, errors.New("not a string")
	}

	var  any
	 := .Scan(, TextFormatCode, []byte(), &)
	if  != nil {
		return nil, 
	}

	return .Encode(, BinaryFormatCode, , )
}