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

package sctp

import (
	
	
	
)

/*
chunkShutdown represents an SCTP Chunk of type chunkShutdown

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Type = 7    | Chunk  Flags  |      Length = 8               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                      Cumulative TSN Ack                       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+.
*/
type chunkShutdown struct {
	chunkHeader
	cumulativeTSNAck uint32
}

const (
	cumulativeTSNAckLength = 4
)

// Shutdown chunk errors.
var (
	ErrInvalidChunkSize     = errors.New("invalid chunk size")
	ErrChunkTypeNotShutdown = errors.New("ChunkType is not of type SHUTDOWN")
)

func ( *chunkShutdown) ( []byte) error {
	if  := .chunkHeader.unmarshal();  != nil {
		return 
	}

	if .typ != ctShutdown {
		return fmt.Errorf("%w: actually is %s", ErrChunkTypeNotShutdown, .typ.String())
	}

	if len(.raw) != cumulativeTSNAckLength {
		return ErrInvalidChunkSize
	}

	.cumulativeTSNAck = binary.BigEndian.Uint32(.raw[0:])

	return nil
}

func ( *chunkShutdown) () ([]byte, error) {
	 := make([]byte, cumulativeTSNAckLength)
	binary.BigEndian.PutUint32([0:], .cumulativeTSNAck)

	.typ = ctShutdown
	.raw = 

	return .chunkHeader.marshal()
}

func ( *chunkShutdown) () ( bool,  error) {
	return false, nil
}

// String makes chunkShutdown printable.
func ( *chunkShutdown) () string {
	return .chunkHeader.String()
}