package cql

// Type represents CQL type codes
type Type uint16

// Authenticators
const (
	AuthenticatorAllowAll = "AllowAllAuthenticator"
	AuthenticatorPassword = "PasswordAuthenticator"
)

// Query flags
const (
	QueryFlagValues                = 0x01
	QueryFlagSkipMetadata          = 0x02
	QueryFlagPageSize              = 0x04
	QueryFlagWithPagingState       = 0x08
	QueryFlagWithSerialConsistency = 0x10
	QueryFlagWithDefaultTimestamp  = 0x20
	QueryFlagWithNameValues        = 0x40
	QueryFlagWithKeyspace          = 0x80
	QueryFlagNowInSeconds          = 0x100 // Protocol v5+
)

// Prepare flags
const (
	PrepareFlagWithKeyspace = 0x01 // Protocol v5+
)

// Batch types
const (
	BatchTypeLogged   = 0
	BatchTypeUnlogged = 1
	BatchTypeCounter  = 2
)

// Batch flags
const (
	BatchFlagWithSerialConsistency = 0x10
	BatchFlagWithDefaultTimestamp  = 0x20
	BatchFlagWithKeyspace          = 0x80
	BatchFlagNowInSeconds          = 0x100 // Protocol v5+
)

// Result metadata flags
const (
	ResultMetadataFlagGlobalTableSpec = 0x0001
	ResultMetadataFlagHasMorePages    = 0x0002
	ResultMetadataFlagNoMetaData      = 0x0004
	ResultMetadataFlagMetaDataChanged = 0x0008
)

// CQL types
const (
	TypeCustom    = 0x0000
	TypeAscii     = 0x0001
	TypeBigint    = 0x0002
	TypeBlob      = 0x0003
	TypeBoolean   = 0x0004
	TypeCounter   = 0x0005
	TypeDecimal   = 0x0006
	TypeDouble    = 0x0007
	TypeFloat     = 0x0008
	TypeInt       = 0x0009
	TypeText      = 0x000A
	TypeTimestamp = 0x000B
	TypeUUID      = 0x000C
	TypeVarchar   = 0x000D
	TypeVarint    = 0x000E
	TypeTimeuuid  = 0x000F
	TypeInet      = 0x0010
	TypeDate      = 0x0011
	TypeTime      = 0x0012
	TypeSmallint  = 0x0013
	TypeTinyint   = 0x0014
	TypeDuration  = 0x0015
	TypeList      = 0x0020
	TypeMap       = 0x0021
	TypeSet       = 0x0022
	TypeUDT       = 0x0030
	TypeTuple     = 0x0031
	TypeVector    = 0x0032 // Protocol v5+
)

// Special values for CQL types
const (
	NullValue  = -1
	UnsetValue = -2 // Protocol v4+
)

// Protocol versions
const (
	ProtoVersion1 byte = 0x01
	ProtoVersion2 byte = 0x02
	ProtoVersion3 byte = 0x03
	ProtoVersion4 byte = 0x04
	ProtoVersion5 byte = 0x05

	// Response versions (with direction bit set)
	ProtoVersion1Response byte = 0x81
	ProtoVersion2Response byte = 0x82
	ProtoVersion3Response byte = 0x83
	ProtoVersion4Response byte = 0x84
	ProtoVersion5Response byte = 0x85

	// Direction mask
	ProtoDirectionRequest  = 0x00
	ProtoDirectionResponse = 0x80
	ProtoVersionMask       = 0x7F
)

// Protocol version capabilities
const (
	// Stream ID ranges
	MaxStreamIDv1v2 = 127   // v1-v2: 7-bit stream IDs (0-127)
	MaxStreamIDv3p  = 32767 // v3+: 15-bit stream IDs (0-32767)

	// Frame sizes
	MaxFrameSize       = 256 * 1024 * 1024 // 256MB
	MaxSegmentPayload  = 0x1FFFF           // 131071 bytes (17 bits)
	FrameHeaderSize    = 9                 // Classic frame header size (v1-v4)
	SegmentHeaderSize  = 6                 // Uncompressed segment header (v5+)
	SegmentHeaderSizeC = 8                 // Compressed segment header (v5+)
	Crc24Size          = 3
	Crc32Size          = 4
)

// Version-specific feature flags
const (
	// Protocol v2+
	FeatureTracing = 1 << iota // Tracing support

	// Protocol v3+
	FeaturePreparedStatements // Prepared statements
	FeatureBatchQueries       // Batch queries
	FeatureCompressionFlags   // Compression at frame level

	// Protocol v4+
	FeatureResultMetadataID // Result metadata ID in prepared
	FeatureCustomPayload    // Custom payload
	FeatureWarnings         // Warnings in frame header
	FeatureUnset            // Unset values

	// Protocol v5+
	FeatureSegmentFormat   // Segment-based framing
	FeatureLargePayloads   // Larger payloads via segments
	FeatureBatchFlagsV5    // Batch flags as uint (not byte)
	FeatureQueryFlagsV5    // Query flags as uint (not byte)
	FeatureNowInSeconds    // Now in seconds parameter
	FeatureKeyspaceInQuery // Keyspace in query
	FeatureVectorType      // Vector data type
)

// Event types
const (
	EventTopologyChange = "TOPOLOGY_CHANGE"
	EventStatusChange   = "STATUS_CHANGE"
	EventSchemaChange   = "SCHEMA_CHANGE"
)

// Schema change targets
const (
	TargetKeyspace  = "KEYSPACE"
	TargetTable     = "TABLE"
	TargetType      = "TYPE"
	TargetFunction  = "FUNCTION"
	TargetAggregate = "AGGREGATE"
)

// Schema change changes
const (
	ChangeCreated = "CREATED"
	ChangeDropped = "DROPPED"
	ChangeUpdated = "UPDATED"
)

// Write types (for error responses)
const (
	WriteTypeSimple        = "SIMPLE"
	WriteTypeBatch         = "BATCH"
	WriteTypeUnloggedBatch = "UNLOGGED_BATCH"
	WriteTypeCounter       = "COUNTER"
	WriteTypeBatchLog      = "BATCH_LOG"
	WriteTypeCas           = "CAS"
	WriteTypeView          = "VIEW"
	WriteTypeCdc           = "CDC"
)
