module Validation.CreatePayment ( validate ) where import Data.Maybe (catMaybes) import Common.Model.CreatePayment (CreatePayment (..), CreatePaymentError (..)) import qualified Validation.Atomic as Atomic validate :: CreatePayment -> Maybe CreatePaymentError validate p = if not . null . catMaybes $ [ nameError, costError ] then Just createPaymentError else Nothing where nameError = Atomic.nonEmpty . _createPayment_name $ p costError = Atomic.nonNullNumber . _createPayment_cost $ p createPaymentError = CreatePaymentError { _createPaymentError_name = nameError , _createPaymentError_cost = costError , _createPaymentError_date = Nothing , _createPaymentError_category = Nothing , _createPaymentError_frequency = Nothing }