export type PermissionSection = "club" | "settings" | "user";

export type PermissionModule =
  | "member"
  | "calendar"
  | "newsletter"
  | "newsletter_config"
  | "protocol"
  | "qualification"
  | "award"
  | "executive_position"
  | "communication_type"
  | "membership_status"
  | "calendar_type"
  | "user"
  | "role"
  | "query"
  | "query_store"
  | "template"
  | "template_usage";

export type PermissionType = "read" | "create" | "update" | "delete";

export type PermissionString =
  | `${PermissionSection}.${PermissionModule}.${PermissionType}` // für spezifische Berechtigungen
  | `${PermissionSection}.${PermissionModule}.*` // für alle Berechtigungen in einem Modul
  | `${PermissionSection}.${PermissionType}` // für spezifische Berechtigungen in einem Abschnitt
  | `${PermissionSection}.*` // für alle Berechtigungen in einem Abschnitt
  | "*"; // für Admin

export type PermissionObject = {
  [section in PermissionSection]?: {
    [module in PermissionModule]?: Array<PermissionType> | "*";
  } & { all?: Array<PermissionType> | "*" };
} & {
  admin?: boolean;
};

export type SectionsAndModulesObject = {
  [section in PermissionSection]: Array<PermissionModule>;
};

export const permissionSections: Array<PermissionSection> = ["club", "settings", "user"];
export const permissionModules: Array<PermissionModule> = [
  "member",
  "calendar",
  "newsletter",
  "newsletter_config",
  "protocol",
  "qualification",
  "award",
  "executive_position",
  "communication_type",
  "membership_status",
  "calendar_type",
  "user",
  "role",
  "query",
  "query_store",
  "template",
  "template_usage",
];
export const permissionTypes: Array<PermissionType> = ["read", "create", "update", "delete"];
export const sectionsAndModules: SectionsAndModulesObject = {
  club: ["member", "calendar", "newsletter", "protocol", "query"],
  settings: [
    "qualification",
    "award",
    "executive_position",
    "communication_type",
    "membership_status",
    "calendar_type",
    "query_store",
    "template",
    "template_usage",
    "newsletter_config",
  ],
  user: ["user", "role"],
};
