module Update.LoggedIn.Monthly
  ( updateMonthly
  ) where

import Model.Action.MonthlyAction exposing (..)
import Model.View.LoggedIn.Monthly exposing (..)

updateMonthly : MonthlyAction -> Monthly -> Monthly
updateMonthly action monthly =
  case action of
    ToggleDetail ->
      { monthly | visibleDetail = not monthly.visibleDetail }
    AddPayment payment ->
      { monthly
      | payments = payment :: monthly.payments
      , visibleDetail = True
      }
    DeletePayment payment ->
      { monthly
      | payments = List.filter (((/=) payment.id) << .id) monthly.payments
      }