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

package sdp

import (
	
	
	
	
)

// Default ext values.
const (
	DefExtMapValueABSSendTime     = 1
	DefExtMapValueTransportCC     = 2
	DefExtMapValueSDESMid         = 3
	DefExtMapValueSDESRTPStreamID = 4

	ABSSendTimeURI           = "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"
	TransportCCURI           = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
	SDESMidURI               = "urn:ietf:params:rtp-hdrext:sdes:mid"
	SDESRTPStreamIDURI       = "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"
	SDESRepairRTPStreamIDURI = "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"
	AudioLevelURI            = "urn:ietf:params:rtp-hdrext:ssrc-audio-level"
)

// ExtMap represents the activation of a single RTP header extension.
type ExtMap struct {
	Value     int
	Direction Direction
	URI       *url.URL
	ExtAttr   *string
}

// Clone converts this object to an Attribute.
func ( *ExtMap) () Attribute {
	return Attribute{Key: "extmap", Value: .string()}
}

// Unmarshal creates an Extmap from a string.
func ( *ExtMap) ( string) error {
	 := strings.SplitN(, ":", 2)
	if len() != 2 {
		return fmt.Errorf("%w: %v", errSyntaxError, )
	}

	 := strings.Fields([1])
	if len() < 2 {
		return fmt.Errorf("%w: %v", errSyntaxError, )
	}

	 := strings.Split([0], "/")
	,  := strconv.ParseInt([0], 10, 64)
	if ( < 1) || ( > 246) {
		return fmt.Errorf("%w: %v -- extmap key must be in the range 1-256", errSyntaxError, [0])
	}
	if  != nil {
		return fmt.Errorf("%w: %v", errSyntaxError, [0])
	}

	var  Direction
	if len() == 2 {
		,  = NewDirection([1])
		if  != nil {
			return 
		}
	}

	,  := url.Parse([1])
	if  != nil {
		return 
	}

	if len() == 3 {
		 := [2]
		.ExtAttr = &
	}

	.Value = int()
	.Direction = 
	.URI = 

	return nil
}

// Marshal creates a string from an ExtMap.
func ( *ExtMap) () string {
	return .Name() + ":" + .string()
}

func ( *ExtMap) () string {
	 := fmt.Sprintf("%d", .Value)
	 := .Direction.String()
	if  != directionUnknownStr {
		 += "/" + 
	}

	if .URI != nil {
		 += " " + .URI.String()
	}

	if .ExtAttr != nil {
		 += " " + *.ExtAttr
	}

	return 
}

// Name returns the constant name of this object.
func ( *ExtMap) () string {
	return "extmap"
}