// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

const Set<FormStatus> _validatedFormStatuses = <FormStatus>{
  FormStatus.valid,
  FormStatus.submissionInProgress,
  FormStatus.submissionSuccess,
  FormStatus.submissionFailure,
  FormStatus.submissionCanceled,
};

/// Enum representing the status of a form at any given point in time.
enum FormStatus {
  /// The form has not been touched.
  pure,

  /// The form has been completely validated.
  valid,

  /// The form contains one or more invalid inputs.
  invalid,

  /// The form is in the process of being submitted.
  submissionInProgress,

  /// The form has been submitted successfully.
  submissionSuccess,

  /// The form submission failed.
  submissionFailure,

  /// The form submission has been canceled.
  submissionCanceled;

  /// Indicates whether the form is untouched.
  bool get isPure => this == FormStatus.pure;

  /// Indicates whether the form is completely validated.
  /// This means the [FormStatus] is strictly:
  /// * `FormStatus.valid`
  bool get isValid => this == FormStatus.valid;

  /// Indicates whether the form has been validated successfully.
  /// This means the [FormStatus] is either:
  /// * `FormStatus.valid`
  /// * `FormStatus.submissionInProgress`
  /// * `FormStatus.submissionSuccess`
  /// * `FormStatus.submissionFailure`
  bool get isValidated => _validatedFormStatuses.contains(this);

  /// Indicates whether the form contains one or more invalid inputs.
  bool get isInvalid => this == FormStatus.invalid;

  /// Indicates whether the form is in the process of being submitted.
  bool get isSubmissionInProgress => this == FormStatus.submissionInProgress;

  /// Indicates whether the form has been submitted successfully.
  bool get isSubmissionSuccess => this == FormStatus.submissionSuccess;

  /// Indicates whether the form submission failed.
  bool get isSubmissionFailure => this == FormStatus.submissionFailure;

  /// Indicates whether the form submission has been canceled.
  bool get isSubmissionCanceled => this == FormStatus.submissionCanceled;
}
