export type RoomVisibility = "PUBLIC" | "FRIENDS" | "ROLE_RESTRICTED" | "EXPLICIT";

type AccessInput = {
  visibility: RoomVisibility;
  isOwner?: boolean;
  isAdmin?: boolean;
  isFriend?: boolean;
  hasRoomRole?: boolean;
  explicitMember?: boolean;
};

export function canEnterRoom(input: AccessInput) {
  if (input.isAdmin || input.isOwner) return true;

  switch (input.visibility) {
    case "PUBLIC":
      return true;
    case "FRIENDS":
      return Boolean(input.isFriend || input.explicitMember);
    case "ROLE_RESTRICTED":
      return Boolean(input.hasRoomRole || input.explicitMember);
    case "EXPLICIT":
      return Boolean(input.explicitMember);
    default:
      return false;
  }
}

export const SYSTEM_PERMISSIONS = [
  "admin.users.manage",
  "admin.roles.manage",
  "admin.rooms.manage",
  "rooms.create",
  "rooms.manage.own",
  "rooms.media.control",
  "friends.manage"
] as const;
