/*
 * SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
 *
 * SPDX-License-Identifier: AGPL-3.0-only
 */
import { PermissionLevel } from '@hedgedoc/commons';

interface DeterminePermissionTestCase {
  description: string;
  isOwner: boolean;
  isRegisteredUser: boolean;
  maxGuestLevel: PermissionLevel;
  userPermission: PermissionLevel;
  everyoneGroupPermission: PermissionLevel;
  loggedInUserPermission: PermissionLevel;
  groupPermission: PermissionLevel;
  result: PermissionLevel;
}

export const determinePermissionTestCases: DeterminePermissionTestCase[] = [
  {
    description: 'owner always has full rights',
    isOwner: true,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.FULL,
  },
  {
    description: 'owner always has full rights (even as a guest)',
    isOwner: true,
    isRegisteredUser: false,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.FULL,
  },
  {
    description: 'access denied if no permission is present',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.DENY,
  },
  {
    description: 'access denied if no permission is present (even as a guest)',
    isOwner: false,
    isRegisteredUser: false,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.DENY,
  },
  {
    description: 'if user has explicit READ permission, logged-in user can READ',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.READ,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.READ,
  },
  {
    description: 'if user has explicit WRITE permission, logged-in user can WRITE',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.WRITE,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.WRITE,
  },
  {
    description: 'if everyone has READ permission, logged-in user can READ',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.READ,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.READ,
  },
  {
    description: 'if everyone has READ permission, guest can READ',
    isOwner: false,
    isRegisteredUser: false,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.READ,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.READ,
  },
  {
    description: 'if everyone has WRITE permission, logged-in user can WRITE',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.WRITE,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.WRITE,
  },
  {
    description: 'if everyone has WRITE permission, guest can WRITE',
    isOwner: false,
    isRegisteredUser: false,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.WRITE,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.WRITE,
  },
  {
    description: 'if everyone has READ permission, logged-in user can READ (max guest level READ)',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.READ,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.READ,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.READ,
  },
  {
    description: 'if everyone has READ permission, guest can READ (max guest level READ)',
    isOwner: false,
    isRegisteredUser: false,
    maxGuestLevel: PermissionLevel.READ,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.READ,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.READ,
  },
  {
    description:
      'if everyone has WRITE permission, logged-in user can WRITE (max guest level READ)',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.READ,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.WRITE,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.WRITE,
  },
  {
    description: 'if everyone has WRITE permission, guest can READ (max guest level READ)',
    isOwner: false,
    isRegisteredUser: false,
    maxGuestLevel: PermissionLevel.READ,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.WRITE,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.READ,
  },
  {
    description: 'if logged-in users have READ permission, logged-in user can READ',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.READ,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.READ,
  },
  {
    description: 'if logged-in users have READ permission, guests are denied',
    isOwner: false,
    isRegisteredUser: false,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.READ,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.DENY,
  },
  {
    description: 'if logged-in users have WRITE permission, logged-in user can WRITE',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.WRITE,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.WRITE,
  },
  {
    description: 'if logged-in users have WRITE permission, guests are denied',
    isOwner: false,
    isRegisteredUser: false,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.WRITE,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.DENY,
  },
  {
    description: 'if user is in group with READ permission, logged-in user can READ',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.READ,
    result: PermissionLevel.READ,
  },
  {
    description: 'if user is in group with WRITE permission, logged-in user can WRITE',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.DENY,
    groupPermission: PermissionLevel.WRITE,
    result: PermissionLevel.WRITE,
  },
  {
    description:
      'highest permission in groups wins (everyone has DENY, logged-in user have READ, group has WRITE -> user can WRITE)',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.DENY,
    loggedInUserPermission: PermissionLevel.READ,
    groupPermission: PermissionLevel.WRITE,
    result: PermissionLevel.WRITE,
  },
  {
    description:
      'highest permission in groups wins (everyone has WRITE, logged-in user have READ, group has DENY -> user can WRITE)',
    isOwner: false,
    isRegisteredUser: true,
    maxGuestLevel: PermissionLevel.FULL,
    userPermission: PermissionLevel.DENY,
    everyoneGroupPermission: PermissionLevel.WRITE,
    loggedInUserPermission: PermissionLevel.READ,
    groupPermission: PermissionLevel.DENY,
    result: PermissionLevel.WRITE,
  },
];
