module Model.View.LoggedIn.Account ( Account , IncomeEdition , initAccount , initIncomeEdition , validateIncome ) where import Result as Result exposing (Result(..)) import Utils.Validation exposing (..) import Model.Translations exposing (..) import Model.Payers exposing (..) type alias Account = { payers : Payers , income : Maybe Int , visibleDetail : Bool , incomeEdition : Maybe IncomeEdition } type alias IncomeEdition = { income : String , error : Maybe String } initAccount : Payers -> Maybe Int -> Account initAccount payers income = { payers = payers , income = income , visibleDetail = False , incomeEdition = Nothing } initIncomeEdition : Int -> IncomeEdition initIncomeEdition income = { income = toString income , error = Nothing } validateIncome : String -> Translations -> Result String Int validateIncome amount translations = amount |> validateNonEmpty (getMessage "IncomeRequired" translations) |> flip Result.andThen (validateNumber (getMessage "IncomeMustBeNonNullNumber" translations) ((/=) 0))