package auth

import "github.com/go-webauthn/webauthn/protocol"

// parseTransports converts JSON-stored transport hint strings back into the
// library's typed slice. Unknown values are dropped silently.
func parseTransports(ss []string) []protocol.AuthenticatorTransport {
	out := make([]protocol.AuthenticatorTransport, 0, len(ss))
	for _, s := range ss {
		switch protocol.AuthenticatorTransport(s) {
		case protocol.USB, protocol.NFC, protocol.BLE, protocol.Internal,
			protocol.Hybrid, protocol.SmartCard:
			out = append(out, protocol.AuthenticatorTransport(s))
		}
	}
	return out
}

func transportsToStrings(ts []protocol.AuthenticatorTransport) []string {
	out := make([]string, 0, len(ts))
	for _, t := range ts {
		out = append(out, string(t))
	}
	return out
}

// protocolAuthenticatorAttachment narrows a free-form stored string to the
// library's typed enum. Empty / unknown returns "" — the credential's
// attachment is informational, not used for validation.
func protocolAuthenticatorAttachment(s string) protocol.AuthenticatorAttachment {
	switch protocol.AuthenticatorAttachment(s) {
	case protocol.Platform, protocol.CrossPlatform:
		return protocol.AuthenticatorAttachment(s)
	}
	return ""
}
