import 'package:formz/formz.dart';

enum TransactionValueValidationError {
  empty('Value empty'),
  invalid('Value invalid');

  final String message;
  const TransactionValueValidationError(this.message);
}

class TransactionValue extends FormzInput<double, TransactionValueValidationError> {
  const TransactionValue.pure() : super.pure(0);
  const TransactionValue.dirty([super.value = 0]) : super.dirty();

  @override
  TransactionValueValidationError? validator(double value) {
    return value.isNaN
      ? TransactionValueValidationError.empty
      : value.isInfinite
        ? TransactionValueValidationError.invalid
        : null;
  }
}