import { IImageInfo } from './common';

export enum Membership {
  Invite = 'invite',
  Knock = 'knock',
  Join = 'join',
  Leave = 'leave',
  Ban = 'ban',
}

export type IMemberContent = {
  avatar_url?: string;
  displayname?: string;
  membership?: Membership;
  reason?: string;
  is_direct?: boolean;
};

export enum StateEvent {
  RoomCanonicalAlias = 'm.room.canonical_alias',
  RoomCreate = 'm.room.create',
  RoomJoinRules = 'm.room.join_rules',
  RoomMember = 'm.room.member',
  RoomThirdPartyInvite = 'm.room.third_party_invite',
  RoomPowerLevels = 'm.room.power_levels',
  RoomName = 'm.room.name',
  RoomTopic = 'm.room.topic',
  RoomAvatar = 'm.room.avatar',
  RoomPinnedEvents = 'm.room.pinned_events',
  RoomEncryption = 'm.room.encryption',
  RoomHistoryVisibility = 'm.room.history_visibility',
  RoomGuestAccess = 'm.room.guest_access',
  RoomServerAcl = 'm.room.server_acl',
  RoomTombstone = 'm.room.tombstone',
  GroupCallPrefix = 'org.matrix.msc3401.call',
  GroupCallMemberPrefix = 'org.matrix.msc3401.call.member',
  // MSC2346 — bridge metadata. Both stable (`m.bridge`) and unstable
  // (`uk.half-shot.bridge`) keys exist in the wild; mautrix-* and most
  // long-running bridges write at least one of them. Used by Vojo to detect
  // bridged rooms (e.g. mautrix-telegram puppet rooms) so we can suppress
  // surfaces that don't translate across the bridge — voice calls being the
  // most obvious example: Telegram has no Matrix-RTC equivalent, so a 1:1
  // bridged room must never expose `DmCallButton`.
  RoomBridge = 'm.bridge',
  RoomBridgeUnstable = 'uk.half-shot.bridge',

  SpaceChild = 'm.space.child',
  SpaceParent = 'm.space.parent',

  PoniesRoomEmotes = 'im.ponies.room_emotes',
  PowerLevelTags = 'in.vojo.room.power_level_tags',
  // Vojo per-room "voice messages allowed" preference. Soft, client-side,
  // Vojo↔Vojo: a participant (1:1) or admin (group) writes `{ enabled: false,
  // disabled_by }` to block voice messages in the room. Absent OR
  // `enabled !== false` ⇒ allowed (default-on). See docs/plans/voice_messages.md.
  VoiceMessages = 'in.vojo.room.voice_messages',
}

export enum MessageEvent {
  RoomMessage = 'm.room.message',
  RoomMessageEncrypted = 'm.room.encrypted',
  Sticker = 'm.sticker',
  RoomRedaction = 'm.room.redaction',
  Reaction = 'm.reaction',
}

export enum RoomType {
  Space = 'm.space',
  Call = 'org.matrix.msc3417.call',
}

export type MSpaceChildContent = {
  via: string[];
  suggested?: boolean;
  order?: string;
};

export enum NotificationType {
  Default = 'default',
  AllMessages = 'all_messages',
  MentionsAndKeywords = 'mentions_and_keywords',
  Mute = 'mute',
}

export type IRoomCreateContent = {
  creator?: string;
  ['m.federate']?: boolean;
  room_version: string;
  type?: string;
  additional_creators?: string[];
  predecessor?: {
    event_id?: string;
    room_id: string;
  };
};

export type GetContentCallback = <T>() => T;

export type RoomToParents = Map<string, Set<string>>;
export type Unread = {
  total: number;
  highlight: number;
  from: Set<string> | null;
};
export type RoomToUnread = Map<string, Unread>;
export type UnreadInfo = {
  roomId: string;
  total: number;
  highlight: number;
};

export type MuteChanges = {
  added: string[];
  removed: string[];
};

export type MemberPowerTagIcon = {
  key?: string;
  info?: IImageInfo;
};
export type MemberPowerTag = {
  name: string;
  color?: string;
  icon?: MemberPowerTagIcon;
};
