package phcformat

import (
	
	
)

// Append appends the given parameters in a PHC string format to dst and returns
// the resulting slice.
//
// The caller is responsible for ensuring that:
//  • name is a sequence of characters in “a-z0-9-”.
//  • version is a sequence of characters in “0-9”.
//  • params is a sequence of comma-separated name and value pairs (separated by
//    equals sign) where name is a sequence of characters in “a-z0-9-” and value
//    is a sequence of characters in “a-zA-Z0-9/+.-”. If version is not set and
//    only a single parameter named “v” is given, to avoid ambiguity, its value
//    must not be a sequence of characters in “0-9” (as in version).
//  • salt is a sequence of characters in “a-zA-Z0-9/+.-”.
//  • output is a sequence of characters in “A-Za-z0-9+/” (base64 character set)
//    and salt is set. That is, it must be a base64-encoded string and implies
//    that salt is set.
func [, , , ,  encode.Appender](
	 []byte,
	 ,
	 option.Of[],
	 option.Of[],
	 option.Of[],
	 option.Of[],
) []byte {
	 := encode.NewString("$")
	 := encode.NewString("$v=")

	 := encode.NewConcat(, )
	 := optionAppenderWithPrefix(, )
	 := optionAppenderWithPrefix(, )
	 := optionAppenderWithPrefix(, )
	 := optionAppenderWithPrefix(, )

	 = .Append()
	 = .Append()
	 = .Append()
	 = .Append()
	 = .Append()

	return 
}

// optionAppenderWithPrefix returns an encode.Appender that, if set, is prefixed
// with the given prefix.
func [,  encode.Appender](
	 ,
	 option.Of[],
) encode.Option[encode.Concat[, ]] {
	if ,  := .Unwrap();  {
		return encode.NewOption(option.Value(encode.NewConcat(, )))
	}
	return encode.NewOption(option.Nil[encode.Concat[, ]]())
}