// 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/>.

// ignore_for_file: strict_raw_type

import 'package:equatable/equatable.dart';
import 'package:wyatt_form_bloc/src/core/enums/form_status.dart';
import 'package:wyatt_form_bloc/src/core/enums/validation_error.dart';
import 'package:wyatt_form_bloc/src/domain/entities/form_input.dart';
import 'package:wyatt_form_bloc/src/domain/entities/form_input_metadata.dart';
import 'package:wyatt_form_bloc/src/domain/form_operations/form_operation.dart';
import 'package:wyatt_form_bloc/src/domain/form_validators/form_validator.dart';
import 'package:wyatt_form_bloc/src/domain/input_validators/form_input_validator.dart';

abstract class WyattForm extends Equatable {
  List<FormInput> get inputs;
  FormValidator get formValidationStrategy;
  String get name;

  bool containsKey(String key);

  FormInput inputOf(String key);
  Validator validatorOf<
      Validator extends FormInputValidator<dynamic, ValidationError>>(
    String key,
  );
  Error? errorOf<Error extends ValidationError>(String key);
  Value? valueOf<Value>(String key);
  FormInputMetadata<Extra> metadataOf<Extra>(String key);

  List<FormInputValidator<Value, Error>>
      asValidatorList<Value, Error extends ValidationError>();

  void updateValidator<Value>(
    String key,
    FormInputValidator<Value?, ValidationError> dirtyValue,
  );

  void updateMetadata<Extra>(
    String key,
    FormInputMetadata<Extra> metadata,
  );

  FormStatus validate();
  WyattForm clone();
  WyattForm operationWith(FormOperation operation, WyattForm other);
  WyattForm reset();

  bool isPureInput(String key);
  bool isValidInput(String key);
  bool isInvalidInput(String key);
}
