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

  /**
   * 
   * @returns {Promise<Array>}
   */
  async fetchModalMachines() {
    return await this.adapter.fetchModalMachines()
  }

  /**
   * 
   * @param {Array} packsNumbers
   * @returns {Promise<Array>}
   */
  async fetchLastMachinesByPackNum(packsNumbers) {
    return await this.adapter.fetchLastMachinesByPackNum(packsNumbers)
  }

  /**
   * @param {Array} machines
   * @returns {Promise<Array>}
   */
  async setModalMachines(machines) {
    const result = await this.store.dispatch('machines/setModalMachines', machines)
    return result
  }

  /**
   * @param {Array} packs
   * @returns {Promise<Array>}
   */
  async setLastMachinesByPackNum(packs) {
    const result = await this.store.dispatch('machines/setLastMachinesByPackNumber', packs)
    return result
  }

  /**
   * 
   * @returns {Promise<Array>}
  */
  async fetchAndSetModalMachines() {
    const machines = await this.fetchModalMachines()
    await this.setModalMachines(machines)
    return machines
  }

  /**
   * 
  * @param {Array} packsNumbers
   * @returns {Promise<Array>}
   */
  async fetchAndSetLastMachinesByPackNum(packsNumbers) {
    const machines = await this.fetchLastMachinesByPackNum(packsNumbers)
    await this.setLastMachinesByPackNum(machines)
    return machines
  }
  
}

export default ServiceOfMachines