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

export const MAX_GUILDS_PREMIUM = 200;
export const MAX_GUILD_CHANNELS = 500;
export const MAX_CHANNELS_PER_CATEGORY = 50;
export const VOICE_CHANNEL_BITRATE_MIN = 8000;
export const VOICE_CHANNEL_BITRATE_MAX = 320000;
export const VOICE_CHANNEL_USER_LIMIT_MIN = 0;
export const VOICE_CHANNEL_USER_LIMIT_MAX = 99;
export const VOICE_CHANNEL_CAMERA_USER_LIMIT = 25;
export const VOICE_CHANNEL_CONNECTION_LIMIT_DEFAULT = 5;
export const VOICE_CHANNEL_CONNECTION_LIMIT_MIN = 1;
export const VOICE_CHANNEL_CONNECTION_LIMIT_MAX = 100;
export const CHANNEL_RATE_LIMIT_PER_USER_MIN = 0;
export const CHANNEL_RATE_LIMIT_PER_USER_MAX = 21600;
export const CHANNEL_TOPIC_MIN_LENGTH = 1;
export const CHANNEL_TOPIC_MAX_LENGTH = 1024;
export const RTC_REGION_ID_MIN_LENGTH = 1;
export const RTC_REGION_ID_MAX_LENGTH = 64;
export const MAX_GUILD_EMOJIS = 500;
export const MAX_GUILD_EMOJIS_ANIMATED = MAX_GUILD_EMOJIS;
export const MAX_GUILD_EMOJIS_STATIC = MAX_GUILD_EMOJIS;
export const MAX_GUILD_EMOJIS_ANIMATED_MORE_EMOJI = MAX_GUILD_EMOJIS;
export const MAX_GUILD_EMOJIS_STATIC_MORE_EMOJI = MAX_GUILD_EMOJIS;
export const MAX_GUILD_STICKERS = 500;
export const MAX_GUILD_STICKERS_MORE_STICKERS = MAX_GUILD_STICKERS;
export const MAX_GUILD_EXPRESSION_SLOTS_UNLIMITED = 999999;
export const MAX_GUILD_INVITES = 1000;
export const MAX_GUILD_MEMBERS = 1000000;
export const MAX_GUILD_MEMBERS_VERY_LARGE_GUILD = 10000000;
export const MAX_INVITE_USES = 100;
export const MAX_INVITE_AGE_SECONDS = 604800;
export const MAX_GUILD_ROLES = 250;
export const MAX_APPLICATIONS_PER_USER = 25;
export const MAX_WEBHOOKS_PER_CHANNEL = 15;
export const MAX_WEBHOOKS_PER_GUILD = 1000;
export const MAX_MESSAGE_LENGTH_PREMIUM = 4000;
export const MAX_MESSAGE_LENGTH_NON_PREMIUM = 2000;
export const MAX_ATTACHMENTS_PER_MESSAGE = 10;
export const MAX_EMBEDS_PER_MESSAGE = 10;
export const MAX_REACTIONS_PER_MESSAGE = 30;
export const MAX_USERS_PER_MESSAGE_REACTION = 1_000_000;
export const MAX_ATTACHMENT_ALT_TEXT_LENGTH = 4096;
export const MAX_KATEX_RENDER_SOURCE_LENGTH = 1024;
export const MAX_KATEX_RENDER_CONTROL_SEQUENCE_COUNT = 64;
export const MAX_CODE_HIGHLIGHT_SOURCE_LENGTH = 50_000;
export const MAX_CODE_HIGHLIGHT_OUTPUT_LENGTH = 200_000;

import {ASSET_FORMAT_POLICY} from '@fluxer/constants/src/AssetFormatPolicy';

export const MAX_BIO_LENGTH = 320;
export const AVATAR_MAX_SIZE = ASSET_FORMAT_POLICY.avatar.maxBytes;
export const MAX_RELATIONSHIPS = 1000;
const MAX_GROUP_DM_MEMBERS = 50;
export const MAX_GROUP_DM_RECIPIENTS = MAX_GROUP_DM_MEMBERS;
export const MAX_GROUP_DM_OTHER_RECIPIENTS = MAX_GROUP_DM_MEMBERS - 1;
export const MAX_PRIVATE_CHANNELS_PER_USER = 250;
export const MAX_GROUP_DMS_PER_USER = 150;
export const MAX_BOOKMARKS_PREMIUM = 300;
export const MAX_BOOKMARKS_NON_PREMIUM = 50;
export const MAX_FAVORITE_MEMES_PREMIUM = 500;
export const MAX_FAVORITE_MEMES_NON_PREMIUM = 50;
export const MAX_FAVORITE_MEME_TAGS = 10;
export const MAX_FAVORITE_GIFS = 10000;
export const MAX_VOICE_MESSAGE_DURATION = 1200;
export const MAX_MEDIA_DURATION_SECONDS = 86400;
export const EMOJI_MAX_SIZE = ASSET_FORMAT_POLICY.emoji.maxBytes;
export const STICKER_MAX_SIZE = ASSET_FORMAT_POLICY.sticker.maxBytes;
export const ATTACHMENT_MAX_SIZE_PREMIUM = 500 * 1024 * 1024;
export const ATTACHMENT_MAX_SIZE_NON_PREMIUM = 25 * 1024 * 1024;
export const ATTACHMENT_MAX_SIZE_BOT = 50 * 1024 * 1024;
export const ATTACHMENT_UPLOAD_CHUNK_THRESHOLD = 10 * 1024 * 1024;
const ATTACHMENT_UPLOAD_MIN_CHUNK_SIZE = 10 * 1024 * 1024;
const ATTACHMENT_UPLOAD_CHUNK_SIZE_STEP = 1 * 1024 * 1024;
const ATTACHMENT_UPLOAD_TARGET_PART_COUNT = 20;
export const ATTACHMENT_UPLOAD_MAX_CHUNKS = 10000;

export function resolveAttachmentUploadPartSize(fileSize: number): number {
	const raw = Math.ceil(fileSize / ATTACHMENT_UPLOAD_TARGET_PART_COUNT);
	const aligned = Math.ceil(raw / ATTACHMENT_UPLOAD_CHUNK_SIZE_STEP) * ATTACHMENT_UPLOAD_CHUNK_SIZE_STEP;
	return Math.max(ATTACHMENT_UPLOAD_MIN_CHUNK_SIZE, aligned);
}

export const MAX_MESSAGES_PER_CHANNEL = 50;
export const MAX_LOADED_MESSAGES = MAX_MESSAGES_PER_CHANNEL * 4;
export const TRUNCATED_MESSAGE_VIEW_SIZE = MAX_LOADED_MESSAGES * 0.5;
export const MAX_MESSAGE_CACHE_SIZE = MAX_MESSAGES_PER_CHANNEL * 5;
export const NEW_MESSAGES_BAR_BUFFER = 32;
export const MIN_TEMP_BAN_DURATION_SECONDS = 60;
export const MAX_TEMP_BAN_DURATION_SECONDS = 2 * 365 * 24 * 60 * 60;
