// Copyright (C) 2023 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/>.

import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';

/// This class contains all the forms used in the authentication process.
abstract class Forms {
  /// Builds a sign in form.
  static WyattForm buildSignInForm(
    FormInputValidator<String?, ValidationError>? customEmailValidator,
    FormInputValidator<String?, ValidationError>? customPasswordValidator,
  ) =>
      WyattFormImpl(
        [
          FormInput(
            AuthFormField.email,
            customEmailValidator ?? const Email.pure(),
          ),
          FormInput(
            AuthFormField.password,
            customPasswordValidator ?? const Password.pure(),
          )
        ],
        name: AuthFormName.signInForm,
      );

  /// Builds a sign up form.
  static WyattForm buildSignUpForm(
    FormInputValidator<String?, ValidationError>? customEmailValidator,
    FormInputValidator<String?, ValidationError>? customPasswordValidator,
    // ignore: strict_raw_type
    List<FormInput>? extraSignUpInputs,
  ) =>
      WyattFormImpl(
        [
          FormInput(
            AuthFormField.email,
            customEmailValidator ?? const Email.pure(),
          ),
          FormInput(
            AuthFormField.password,
            customPasswordValidator ?? const Password.pure(),
          ),
          ...extraSignUpInputs ?? []
        ],
        name: AuthFormName.signUpForm,
      );

  /// Builds a password reset form.
  static WyattForm buildPasswordResetForm(
    FormInputValidator<String?, ValidationError>? customEmailValidator,
  ) =>
      WyattFormImpl(
        [
          FormInput(
            AuthFormField.email,
            customEmailValidator ?? const Email.pure(),
          ),
        ],
        name: AuthFormName.passwordResetForm,
      );

  /// Builds an edit account form.
  static WyattForm buildEditAccountForm(
    FormInputValidator<String?, ValidationError>? customEmailValidator,
    FormInputValidator<String?, ValidationError>? customPasswordValidator,
    // ignore: strict_raw_type
    List<FormInput>? extraEditAccountInputs,
  ) =>
      WyattFormImpl(
        [
          FormInput(
            AuthFormField.email,
            customEmailValidator ?? const Email.pure(),
            metadata: const FormInputMetadata(isRequired: false),
          ),
          FormInput(
            AuthFormField.password,
            customPasswordValidator ?? const Password.pure(),
            metadata: const FormInputMetadata(isRequired: false),
          ),
          ...extraEditAccountInputs ?? []
        ],
        validationStrategy: const OnlyRequiredInputValidator(),
        name: AuthFormName.editAccountForm,
      );
}
