module Dialog.AddIncome.Model exposing ( Model , init , initialAdd , initialClone , initialEdit , validation ) import Date exposing (Date) import View.Date as Date import Form exposing (Form) import Form.Field as Field exposing (Field) import Form.Validate as Validate exposing (Validation) import Validation import Model.Translations exposing (Translations) import Model.Income exposing (Income, IncomeId) type alias Model = { id : Maybe IncomeId , amount : Int , date : Date } init : Form String Model init = Form.initial [] validation initialAdd : Translations -> Date -> List (String, Field) initialAdd translations date = [ ("date", Field.string (Date.shortView date translations)) ] initialClone : Translations -> Date -> Income -> List (String, Field) initialClone translations date income = [ ("amount", Field.string (toString income.amount)) , ("date", Field.string (Date.shortView date translations)) ] initialEdit : Translations -> IncomeId -> Income -> List (String, Field) initialEdit translations incomeId income = [ ("id", Field.string (toString incomeId)) , ("amount", Field.string (toString income.amount)) , ("date", Field.string (Date.shortView (Date.fromTime income.time) translations)) ] validation : Validation String Model validation = Validate.map3 Model (Validate.field "id" (Validate.maybe Validate.int)) (Validate.field "amount" (Validate.int |> Validate.andThen (Validate.minInt 1))) (Validate.field "date" Validation.date)