// SPDX-License-Identifier: AGPL-3.0-or-later

import type {ValueOf} from '@fluxer/constants/src/ValueOf';

export const GatewayOpcodes = {
	DISPATCH: 0,
	HEARTBEAT: 1,
	IDENTIFY: 2,
	PRESENCE_UPDATE: 3,
	VOICE_STATE_UPDATE: 4,
	VOICE_SERVER_PING: 5,
	RESUME: 6,
	RECONNECT: 7,
	REQUEST_GUILD_MEMBERS: 8,
	INVALID_SESSION: 9,
	HELLO: 10,
	HEARTBEAT_ACK: 11,
	GATEWAY_ERROR: 12,
	LAZY_REQUEST: 14,
	REQUEST_GUILD_COUNTS: 15,
	REQUEST_CHANNEL_MEMBER_COUNTS: 16,
} as const;
export const LARGE_GUILD_THRESHOLD = 250;
export const MEMBER_LIST_RANGE_MAX_END = 100000;
export const MEMBER_LIST_RANGE_MAX_SPAN = 99;
export const MEMBER_LIST_RANGE_PAGE_SIZE = MEMBER_LIST_RANGE_MAX_SPAN + 1;
export const MEMBER_LIST_RANGE_WINDOW_OVERSCAN_PAGES = 1;
export const GatewayIdentifyFlags = {
	DEBOUNCE_MESSAGE_REACTIONS: 1 << 1,
} as const;
export const GatewayCloseCodes = {
	UNKNOWN_ERROR: 4000,
	UNKNOWN_OPCODE: 4001,
	DECODE_ERROR: 4002,
	NOT_AUTHENTICATED: 4003,
	AUTHENTICATION_FAILED: 4004,
	ALREADY_AUTHENTICATED: 4005,
	INVALID_SEQ: 4007,
	RATE_LIMITED: 4008,
	SESSION_TIMEOUT: 4009,
	INVALID_SHARD: 4010,
	SHARDING_REQUIRED: 4011,
	INVALID_API_VERSION: 4012,
} as const;
export const GatewayErrorCodes = {
	DM_INVALID_CHANNEL_TYPE: 'DM_INVALID_CHANNEL_TYPE',
	DM_NOT_RECIPIENT: 'DM_NOT_RECIPIENT',
	UNKNOWN_ERROR: 'UNKNOWN_ERROR',
	VOICE_CHANNEL_FULL: 'VOICE_CHANNEL_FULL',
	VOICE_CHANNEL_NOT_FOUND: 'VOICE_CHANNEL_NOT_FOUND',
	VOICE_CONNECTION_LIMIT_REACHED: 'VOICE_CONNECTION_LIMIT_REACHED',
	VOICE_CONNECTION_NOT_FOUND: 'VOICE_CONNECTION_NOT_FOUND',
	VOICE_GUILD_ID_MISSING: 'VOICE_GUILD_ID_MISSING',
	VOICE_GUILD_NOT_FOUND: 'VOICE_GUILD_NOT_FOUND',
	VOICE_INVALID_CHANNEL_ID: 'VOICE_INVALID_CHANNEL_ID',
	VOICE_INVALID_CHANNEL_TYPE: 'VOICE_INVALID_CHANNEL_TYPE',
	VOICE_INVALID_GUILD_ID: 'VOICE_INVALID_GUILD_ID',
	VOICE_INVALID_STATE: 'VOICE_INVALID_STATE',
	VOICE_INVALID_USER_ID: 'VOICE_INVALID_USER_ID',
	VOICE_MEMBER_NOT_FOUND: 'VOICE_MEMBER_NOT_FOUND',
	VOICE_MEMBER_TIMED_OUT: 'VOICE_MEMBER_TIMED_OUT',
	VOICE_MISSING_CONNECTION_ID: 'VOICE_MISSING_CONNECTION_ID',
	VOICE_PERMISSION_DENIED: 'VOICE_PERMISSION_DENIED',
	VOICE_TOKEN_FAILED: 'VOICE_TOKEN_FAILED',
	VOICE_UNCLAIMED_ACCOUNT: 'VOICE_UNCLAIMED_ACCOUNT',
	VOICE_USER_MISMATCH: 'VOICE_USER_MISMATCH',
	VOICE_USER_NOT_IN_VOICE: 'VOICE_USER_NOT_IN_VOICE',
} as const;

export type GatewayErrorCode = ValueOf<typeof GatewayErrorCodes>;
