#ifndef MS_RTC_SCTP_OUT_OF_RESOURCE_ERROR_CAUSE_HPP
#define MS_RTC_SCTP_OUT_OF_RESOURCE_ERROR_CAUSE_HPP

#include "common.hpp"
#include "RTC/SCTP/packet/ErrorCause.hpp"

namespace RTC
{
	namespace SCTP
	{
		/**
		 * SCTP Out of Resource Error Cause (OUT_OF_RESOURCE) (4)
		 *
		 * @see RFC 9260.
		 *
		 *  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
		 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
		 * |        Cause Code = 4         |       Cause Length = 4        |
		 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
		 */

		// Forward declaration.
		class Chunk;

		class OutOfResourceErrorCause : public ErrorCause
		{
			// We need that Chunk calls protected and private methods in this class.
			friend class Chunk;

		public:
			/**
			 * Parse a OutOfResourceErrorCause.
			 *
			 * @remarks
			 * `bufferLength` may exceed the exact length of the Error Cause.
			 */
			static OutOfResourceErrorCause* Parse(const uint8_t* buffer, size_t bufferLength);

			/**
			 * Create a OutOfResourceErrorCause.
			 *
			 * @remarks
			 * `bufferLength` could be greater than the Error Cause real length.
			 */
			static OutOfResourceErrorCause* Factory(uint8_t* buffer, size_t bufferLength);

		private:
			/**
			 * Parse a OutOfResourceErrorCause.
			 *
			 * @remarks
			 * To be used only by `Chunk::ParseErrorCauses()`.
			 */
			static OutOfResourceErrorCause* ParseStrict(
			  const uint8_t* buffer, size_t bufferLength, uint16_t causeLength, uint8_t padding);

		private:
			/**
			 * Only used by Parse(), ParseStrict() and Factory() static methods.
			 */
			OutOfResourceErrorCause(uint8_t* buffer, size_t bufferLength);

		public:
			~OutOfResourceErrorCause() override;

			void Dump(int indentation = 0) const final;

			OutOfResourceErrorCause* Clone(uint8_t* buffer, size_t bufferLength) const final;

		protected:
			OutOfResourceErrorCause* SoftClone(const uint8_t* buffer) const final;
		};
	} // namespace SCTP
} // namespace RTC

#endif
