// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package webrtc

import (
	
	
)

// ICECredentialType indicates the type of credentials used to connect to
// an ICE server.
type ICECredentialType int

const (
	// ICECredentialTypePassword describes username and password based
	// credentials as described in https://tools.ietf.org/html/rfc5389.
	ICECredentialTypePassword ICECredentialType = iota

	// ICECredentialTypeOauth describes token based credential as described
	// in https://tools.ietf.org/html/rfc7635.
	ICECredentialTypeOauth
)

// This is done this way because of a linter.
const (
	iceCredentialTypePasswordStr = "password"
	iceCredentialTypeOauthStr    = "oauth"
)

func newICECredentialType( string) (ICECredentialType, error) {
	switch  {
	case iceCredentialTypePasswordStr:
		return ICECredentialTypePassword, nil
	case iceCredentialTypeOauthStr:
		return ICECredentialTypeOauth, nil
	default:
		return ICECredentialTypePassword, errInvalidICECredentialTypeString
	}
}

func ( ICECredentialType) () string {
	switch  {
	case ICECredentialTypePassword:
		return iceCredentialTypePasswordStr
	case ICECredentialTypeOauth:
		return iceCredentialTypeOauthStr
	default:
		return ErrUnknownType.Error()
	}
}

// UnmarshalJSON parses the JSON-encoded data and stores the result.
func ( *ICECredentialType) ( []byte) error {
	var  string
	if  := json.Unmarshal(, &);  != nil {
		return 
	}

	,  := newICECredentialType()
	if  != nil {
		return fmt.Errorf("%w: (%s)", , )
	}

	* = 

	return nil
}

// MarshalJSON returns the JSON encoding.
func ( ICECredentialType) () ([]byte, error) {
	return json.Marshal(.String())
}