import { processCellarSpoilage } from './processCellarSpoilage.js'

/**
 * @returns state
 */
export const processCellar = (state: farmhand.state) => {
  state = processCellarSpoilage(state)
  const { cellarInventory } = state

  const newCellarInventory = [...cellarInventory]

  for (let i = 0; i < newCellarInventory.length; i++) {
    const keg = newCellarInventory[i]

    newCellarInventory[i] = {
      ...keg,
      daysUntilMature: keg.daysUntilMature - 1,
    }
  }

  state = { ...state, cellarInventory: newCellarInventory }

  return state
}
