module Update.LoggedIn.Add
  ( AddPaymentAction(..)
  , updateAddPayment
  ) where

import Model.View.LoggedIn.Add exposing (..)

type AddPaymentAction =
  UpdateName String
  | UpdateCost String
  | AddError (Maybe String) (Maybe String)
  | ToggleFrequency

updateAddPayment : AddPaymentAction -> AddPayment -> AddPayment
updateAddPayment action addPayment =
  case action of
    UpdateName name ->
      { addPayment | name = name }
    UpdateCost cost ->
      { addPayment | cost = cost }
    AddError nameError costError ->
      { addPayment
      | nameError = nameError
      , costError = costError
      }
    ToggleFrequency ->
      { addPayment
      | frequency = if addPayment.frequency == Punctual then Monthly else Punctual
      }