package wal

// WAL file format constants.

const (
	// WalMagic is the file type identifier for WAL segment files ("WALK").
	WalMagic uint32 = 0x57414C4B

	// WalFormatVersion is the WAL file format version. First version is 1.
	WalFormatVersion uint16 = 1

	// WalFileHeaderSize is the size of the WAL file header in bytes.
	// Fields: magic(4) + formatVersion(2) + headerSize(2) + blockSize(4) +
	// segmentID(8) + startSequence(8) + headerCRC(4) = 32.
	WalFileHeaderSize = 32

	// WalBlockSize is the fixed size of each WAL block in bytes (32 KB).
	WalBlockSize = 32 * 1024

	// PhysicalRecordHeaderSize is the size of a physical record header in bytes.
	// Fields: crc32c(4) + length(2) + type(1) = 7.
	PhysicalRecordHeaderSize = 7

	// WalBatchHeaderSize is the size of a WAL batch header in bytes.
	// Fields: flags(2) + baseSequence(8) + entryCount(4) + entriesSize(4) = 18.
	WalBatchHeaderSize = 18

	// MaxWalBatchEntryCount limits the number of entries in a single batch.
	MaxWalBatchEntryCount uint32 = 10000

	// MaxWalBatchEntriesSize limits the total size of the entries region in bytes (4 MB).
	MaxWalBatchEntriesSize uint32 = 4 * 1024 * 1024

	// MaxWalKeyBytes limits the size of a single key in bytes (4 KB).
	MaxWalKeyBytes uint32 = 4 * 1024

	// MaxWalInlineValueBytes limits the size of an inline value in bytes (4 KB).
	// Values exceeding this must use ValueLogPointer.
	MaxWalInlineValueBytes uint32 = 4 * 1024

	// MaxWalVarintBytes is the maximum encoded length of a varint field.
	MaxWalVarintBytes = 5

	// DefaultMaxWalSegmentSize is the default maximum size of a WAL segment file (64 MB).
	DefaultMaxWalSegmentSize uint64 = 64 * 1024 * 1024
)

// Fragment types for physical records.
const (
	// RecInvalid is an illegal fragment type used for corruption detection.
	RecInvalid uint8 = 0
	// RecFull indicates a complete WAL batch in a single physical record.
	RecFull uint8 = 1
	// RecFirst is the first fragment of a multi-record WAL batch.
	RecFirst uint8 = 2
	// RecMiddle is a middle fragment (may appear zero or more times).
	RecMiddle uint8 = 3
	// RecLast is the last fragment of a multi-record WAL batch.
	RecLast uint8 = 4
)

// OpType represents the operation type of a WAL entry.
const (
	// OpInvalid is an illegal operation type used for corruption detection.
	OpInvalid uint8 = 0
	// OpPut represents a key-value put operation.
	OpPut uint8 = 1
	// OpDelete represents a key deletion operation.
	OpDelete uint8 = 2
)

// ValueKind represents how the value field is encoded in a WAL entry.
const (
	// VKNone indicates no value (used with Delete operations).
	VKNone uint8 = 0
	// VKInline indicates the value field contains inline user bytes.
	VKInline uint8 = 1
	// VKValueLogPointer indicates the value field contains an encoded Value Log pointer.
	VKValueLogPointer uint8 = 2
)
