import { DataPersisterArgs, HookPersister } from '~/types/interfaces'
import BaseHook from '~/services/data/hooks/baseHook'
import DataPersister from "~/services/data/dataPersister";

/**
 * Access profile (and its embed organization profile) shall be re-fetched after some
 * data updates
 */
class PostPersistProfileRefresh extends BaseHook implements HookPersister {
  public static  priority = 10

  async invoke (_args: DataPersisterArgs): Promise<any> {
    await (this.parent as DataPersister).fetchProfile()
  }

  static support (_args: DataPersisterArgs): boolean {
    return (typeof _args.model !== 'undefined') &&
      ['accesses', 'organizations', 'parameters', 'subdomains'].includes(_args.model.entity)
  }
}

export default PostPersistProfileRefresh
