const { v4: uuid } = require('uuid');

module.exports = {
  /**
   * @param{import("sequelize").QueryInterface} queryInterface
   * @return {Promise<void>}
   */
  async up(queryInterface) {
    const createdAt = new Date();
    const updatedAt = new Date();

    /** @type {Map<string, string>} */
    const idMap = new Map();

    /**
     * @param {string} key
     * @return {string}
     */
    function getId(key) {
      if (idMap.has(key)) {
        return idMap.get(key);
      }
      const id = uuid();
      idMap.set(key, id);
      return id;
    }

    await queryInterface.bulkInsert('roles', [
      {
        id: getId('Administrator'),
        name: 'Administrator',
        createdAt,
        updatedAt,
      },

      {
        id: getId('PlatformOwner'),
        name: 'Platform Owner',
        createdAt,
        updatedAt,
      },

      {
        id: getId('AccountManager'),
        name: 'Account Manager',
        createdAt,
        updatedAt,
      },

      {
        id: getId('TourDesigner'),
        name: 'Tour Designer',
        createdAt,
        updatedAt,
      },

      {
        id: getId('ContentReviewer'),
        name: 'Content Reviewer',
        createdAt,
        updatedAt,
      },

      {
        id: getId('AnalyticsViewer'),
        name: 'Analytics Viewer',
        createdAt,
        updatedAt,
      },

      { id: getId('Public'), name: 'Public', createdAt, updatedAt },
    ]);

    /**
     * @param {string} name
     */
    function createPermissions(name) {
      return [
        {
          id: getId(`CREATE_${name.toUpperCase()}`),
          createdAt,
          updatedAt,
          name: `CREATE_${name.toUpperCase()}`,
        },
        {
          id: getId(`READ_${name.toUpperCase()}`),
          createdAt,
          updatedAt,
          name: `READ_${name.toUpperCase()}`,
        },
        {
          id: getId(`UPDATE_${name.toUpperCase()}`),
          createdAt,
          updatedAt,
          name: `UPDATE_${name.toUpperCase()}`,
        },
        {
          id: getId(`DELETE_${name.toUpperCase()}`),
          createdAt,
          updatedAt,
          name: `DELETE_${name.toUpperCase()}`,
        },
      ];
    }

    const entities = [
      'users',
      'roles',
      'permissions',
      'projects',
      'project_memberships',
      'assets',
      'asset_variants',
      'presigned_url_requests',
      'tour_pages',
      'project_audio_tracks',
      'publish_events',
      'pwa_caches',
      'access_logs',
    ];
    await queryInterface.bulkInsert(
      'permissions',
      entities.flatMap(createPermissions),
    );
    await queryInterface.bulkInsert('permissions', [
      {
        id: getId(`READ_API_DOCS`),
        createdAt,
        updatedAt,
        name: `READ_API_DOCS`,
      },
    ]);
    await queryInterface.bulkInsert('permissions', [
      {
        id: getId(`CREATE_SEARCH`),
        createdAt,
        updatedAt,
        name: `CREATE_SEARCH`,
      },
    ]);

    await queryInterface.sequelize
      .query(`CREATE TABLE IF NOT EXISTS "rolesPermissionsPermissions"
(
"createdAt"           timestamp with time zone not null,
"updatedAt"           timestamp with time zone not null,
"roles_permissionsId" uuid                     not null,
"permissionId"        uuid                     not null,
primary key ("roles_permissionsId", "permissionId"),
constraint "rolesPermissionsPermissions_roles_permissions_fk"
  foreign key ("roles_permissionsId") references "roles"("id")
  on delete cascade on update cascade,
constraint "rolesPermissionsPermissions_permission_fk"
  foreign key ("permissionId") references "permissions"("id")
  on delete cascade on update cascade
);`);

    await queryInterface.sequelize.query(
      'CREATE INDEX IF NOT EXISTS "rolesPermissionsPermissions_permission_idx" ON "rolesPermissionsPermissions" ("permissionId");',
    );

    await queryInterface.bulkInsert('rolesPermissionsPermissions', [
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_USERS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_USERS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_USERS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_USERS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_USERS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_USERS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_USERS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_USERS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_USERS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('UPDATE_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('CREATE_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('UPDATE_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('CREATE_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('CREATE_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('UPDATE_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('CREATE_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('UPDATE_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('CREATE_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('UPDATE_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('CREATE_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('UPDATE_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('CREATE_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('UPDATE_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('UPDATE_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('UPDATE_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('UPDATE_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('UPDATE_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_ACCESS_LOGS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('READ_ACCESS_LOGS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('UPDATE_ACCESS_LOGS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('DELETE_ACCESS_LOGS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('READ_ACCESS_LOGS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('READ_ACCESS_LOGS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('READ_ACCESS_LOGS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('READ_ACCESS_LOGS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('PlatformOwner'),
        permissionId: getId('CREATE_SEARCH'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AccountManager'),
        permissionId: getId('CREATE_SEARCH'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('TourDesigner'),
        permissionId: getId('CREATE_SEARCH'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('ContentReviewer'),
        permissionId: getId('CREATE_SEARCH'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('AnalyticsViewer'),
        permissionId: getId('CREATE_SEARCH'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_USERS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_USERS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_USERS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_USERS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_ROLES'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_ROLES'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_ROLES'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_ROLES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_PERMISSIONS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_PERMISSIONS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_PERMISSIONS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_PERMISSIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_PROJECTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_PROJECTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_PROJECTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_PROJECTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_PROJECT_MEMBERSHIPS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_PROJECT_MEMBERSHIPS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_PROJECT_MEMBERSHIPS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_PROJECT_MEMBERSHIPS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_ASSETS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_ASSETS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_ASSETS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_ASSETS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_ASSET_VARIANTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_ASSET_VARIANTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_ASSET_VARIANTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_ASSET_VARIANTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_PRESIGNED_URL_REQUESTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_PRESIGNED_URL_REQUESTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_PRESIGNED_URL_REQUESTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_PRESIGNED_URL_REQUESTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_TOUR_PAGES'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_TOUR_PAGES'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_TOUR_PAGES'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_TOUR_PAGES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_PAGE_ELEMENTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_PAGE_ELEMENTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_PAGE_ELEMENTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_PAGE_ELEMENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_PAGE_LINKS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_PAGE_LINKS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_PAGE_LINKS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_PAGE_LINKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_TRANSITIONS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_TRANSITIONS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_TRANSITIONS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_TRANSITIONS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_PROJECT_AUDIO_TRACKS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_PROJECT_AUDIO_TRACKS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_PROJECT_AUDIO_TRACKS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_PROJECT_AUDIO_TRACKS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_PUBLISH_EVENTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_PUBLISH_EVENTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_PUBLISH_EVENTS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_PUBLISH_EVENTS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_PWA_CACHES'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_PWA_CACHES'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_PWA_CACHES'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_PWA_CACHES'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_ACCESS_LOGS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_ACCESS_LOGS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('UPDATE_ACCESS_LOGS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('DELETE_ACCESS_LOGS'),
      },

      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('READ_API_DOCS'),
      },
      {
        createdAt,
        updatedAt,
        roles_permissionsId: getId('Administrator'),
        permissionId: getId('CREATE_SEARCH'),
      },
    ]);

    await queryInterface.sequelize.query(
      `UPDATE "users" SET "app_roleId"='${getId('SuperAdmin')}' WHERE "email"='super_admin@flatlogic.com'`,
    );
    await queryInterface.sequelize.query(
      `UPDATE "users" SET "app_roleId"='${getId('Administrator')}' WHERE "email"='admin@flatlogic.com'`,
    );

    await queryInterface.sequelize.query(
      `UPDATE "users" SET "app_roleId"='${getId('PlatformOwner')}' WHERE "email"='client@hello.com'`,
    );
    await queryInterface.sequelize.query(
      `UPDATE "users" SET "app_roleId"='${getId('AccountManager')}' WHERE "email"='john@doe.com'`,
    );
  },
};
