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

package protocol

import (
	
	
	
)

var (
	errBufferTooSmall    = &TemporaryError{Err: errors.New("buffer is too small")} //nolint:goerr113
	errInvalidCipherSpec = &FatalError{Err: errors.New("cipher spec invalid")}     //nolint:goerr113
)

// FatalError indicates that the DTLS connection is no longer available.
// It is mainly caused by wrong configuration of server or client.
type FatalError struct {
	Err error
}

// InternalError indicates and internal error caused by the implementation, and the DTLS connection is no longer available.
// It is mainly caused by bugs or tried to use unimplemented features.
type InternalError struct {
	Err error
}

// TemporaryError indicates that the DTLS connection is still available, but the request was failed temporary.
type TemporaryError struct {
	Err error
}

// TimeoutError indicates that the request was timed out.
type TimeoutError struct {
	Err error
}

// HandshakeError indicates that the handshake failed.
type HandshakeError struct {
	Err error
}

// Timeout implements net.Error.Timeout()
func (*FatalError) () bool { return false }

// Temporary implements net.Error.Temporary()
func (*FatalError) () bool { return false }

// Unwrap implements Go1.13 error unwrapper.
func ( *FatalError) () error { return .Err }

func ( *FatalError) () string { return fmt.Sprintf("dtls fatal: %v", .Err) }

// Timeout implements net.Error.Timeout()
func (*InternalError) () bool { return false }

// Temporary implements net.Error.Temporary()
func (*InternalError) () bool { return false }

// Unwrap implements Go1.13 error unwrapper.
func ( *InternalError) () error { return .Err }

func ( *InternalError) () string { return fmt.Sprintf("dtls internal: %v", .Err) }

// Timeout implements net.Error.Timeout()
func (*TemporaryError) () bool { return false }

// Temporary implements net.Error.Temporary()
func (*TemporaryError) () bool { return true }

// Unwrap implements Go1.13 error unwrapper.
func ( *TemporaryError) () error { return .Err }

func ( *TemporaryError) () string { return fmt.Sprintf("dtls temporary: %v", .Err) }

// Timeout implements net.Error.Timeout()
func (*TimeoutError) () bool { return true }

// Temporary implements net.Error.Temporary()
func (*TimeoutError) () bool { return true }

// Unwrap implements Go1.13 error unwrapper.
func ( *TimeoutError) () error { return .Err }

func ( *TimeoutError) () string { return fmt.Sprintf("dtls timeout: %v", .Err) }

// Timeout implements net.Error.Timeout()
func ( *HandshakeError) () bool {
	var  net.Error
	if errors.As(.Err, &) {
		return .Timeout()
	}
	return false
}

// Temporary implements net.Error.Temporary()
func ( *HandshakeError) () bool {
	var  net.Error
	if errors.As(.Err, &) {
		return .Temporary() //nolint
	}
	return false
}

// Unwrap implements Go1.13 error unwrapper.
func ( *HandshakeError) () error { return .Err }

func ( *HandshakeError) () string { return fmt.Sprintf("handshake error: %v", .Err) }