class UsersOfServices {
  constructor(adapter, store) {
    this.adapter = adapter
    this.store = store
  }

  /**
   *
   * @param {Array} users
   * @returns {Promise<Array>}
   */
  async saveSiteUsers(users) {
    await this.store.dispatch('users/saveSiteUsers', users)
    return users
  }

  /**
   *
   * @param {Array} users
   * @returns {Promise<Array>}
   */
  async saveUsersWithoutSite(users) {
    await this.store.dispatch('users/saveUsersWithoutSite', users)
    return users
  }

  /**
   *
   * @param serviceId
   * @returns {Promise<void>}
   */
  async fetchUsersByService(serviceId) {
    const users = await this.adapter.getUsersByServiceId(serviceId)
    await this.saveSiteUsers(users)
    return users
  }
}

export default UsersOfServices