import { RolesBuilder } from 'nest-access-control';

export enum AppRoles {
  GUEST = 'GUEST',
  PRODUCT = 'PRODUCT',
  SYSTEM_ADMIIN = 'SYSTEM_ADMIN',
}

const ALL_TABLES = ['source', 'tasklog', 'log', 'game', 'role'];

export const roles: RolesBuilder = new RolesBuilder();
roles
  .grant(AppRoles.GUEST)
  .readAny(ALL_TABLES, ['*'])
  .grant(AppRoles.PRODUCT) // define new or modify existing role. also takes an array.
  .extend(AppRoles.GUEST)
  .createAny(ALL_TABLES) // equivalent to .createOwn('product', ['*'])
  .updateAny(ALL_TABLES)
  .deleteAny(ALL_TABLES, ['*'])
  .grant(AppRoles.SYSTEM_ADMIIN) // switch to another role without breaking the chain
  .extend(AppRoles.PRODUCT)
  .createAny(ALL_TABLES)
  .updateAny(ALL_TABLES) // explicitly defined attributes
  .deleteAny(ALL_TABLES, ['*']);
