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

package sdp

import (
	
)

// TimeDescription describes "t=", "r=" fields of the session description
// which are used to specify the start and stop times for a session as well as
// repeat intervals and durations for the scheduled session.
type TimeDescription struct {
	// t=<start-time> <stop-time>
	// https://tools.ietf.org/html/rfc4566#section-5.9
	Timing Timing

	// r=<repeat interval> <active duration> <offsets from start-time>
	// https://tools.ietf.org/html/rfc4566#section-5.10
	RepeatTimes []RepeatTime
}

// Timing defines the "t=" field's structured representation for the start and
// stop times.
type Timing struct {
	StartTime uint64
	StopTime  uint64
}

func ( Timing) () string {
	return stringFromMarshal(.marshalInto, .marshalSize)
}

func ( Timing) ( []byte) []byte {
	 = append(strconv.AppendUint(, .StartTime, 10), ' ')

	return strconv.AppendUint(, .StopTime, 10)
}

func ( Timing) () ( int) {
	return lenUint(.StartTime) + 1 + lenUint(.StopTime)
}

// RepeatTime describes the "r=" fields of the session description which
// represents the intervals and durations for repeated scheduled sessions.
type RepeatTime struct {
	Interval int64
	Duration int64
	Offsets  []int64
}

func ( RepeatTime) () string {
	return stringFromMarshal(.marshalInto, .marshalSize)
}

func ( RepeatTime) ( []byte) []byte {
	 = strconv.AppendInt(, .Interval, 10)
	 = append(, ' ')
	 = strconv.AppendInt(, .Duration, 10)
	for ,  := range .Offsets {
		 = append(, ' ')
		 = strconv.AppendInt(, , 10)
	}

	return 
}

func ( RepeatTime) () ( int) {
	 = lenInt(.Interval)
	 += 1 + lenInt(.Duration)
	for ,  := range .Offsets {
		 += 1 + lenInt()
	}

	return
}