import 'package:equatable/equatable.dart';

enum FormW4Status { initial, submitting, success, failure }

class FormW4State extends Equatable {
  final int currentStep;
  
  // Personal Info
  final String firstName;
  final String lastName;
  final String ssn;
  final String address;
  final String cityStateZip;

  // Form Data
  final String filingStatus;
  final bool multipleJobs;
  
  // Dependents
  final int qualifyingChildren;
  final int otherDependents;
  
  // Adjustments
  final String otherIncome;
  final String deductions;
  final String extraWithholding;

  final String signature;
  final FormW4Status status;
  final String? errorMessage;

  const FormW4State({
    this.currentStep = 0,
    this.firstName = '',
    this.lastName = '',
    this.ssn = '',
    this.address = '',
    this.cityStateZip = '',
    this.filingStatus = '',
    this.multipleJobs = false,
    this.qualifyingChildren = 0,
    this.otherDependents = 0,
    this.otherIncome = '',
    this.deductions = '',
    this.extraWithholding = '',
    this.signature = '',
    this.status = FormW4Status.initial,
    this.errorMessage,
  });

  FormW4State copyWith({
    int? currentStep,
    String? firstName,
    String? lastName,
    String? ssn,
    String? address,
    String? cityStateZip,
    String? filingStatus,
    bool? multipleJobs,
    int? qualifyingChildren,
    int? otherDependents,
    String? otherIncome,
    String? deductions,
    String? extraWithholding,
    String? signature,
    FormW4Status? status,
    String? errorMessage,
  }) {
    return FormW4State(
      currentStep: currentStep ?? this.currentStep,
      firstName: firstName ?? this.firstName,
      lastName: lastName ?? this.lastName,
      ssn: ssn ?? this.ssn,
      address: address ?? this.address,
      cityStateZip: cityStateZip ?? this.cityStateZip,
      filingStatus: filingStatus ?? this.filingStatus,
      multipleJobs: multipleJobs ?? this.multipleJobs,
      qualifyingChildren: qualifyingChildren ?? this.qualifyingChildren,
      otherDependents: otherDependents ?? this.otherDependents,
      otherIncome: otherIncome ?? this.otherIncome,
      deductions: deductions ?? this.deductions,
      extraWithholding: extraWithholding ?? this.extraWithholding,
      signature: signature ?? this.signature,
      status: status ?? this.status,
      errorMessage: errorMessage ?? this.errorMessage,
    );
  }

  int get totalCredits => (qualifyingChildren * 2000) + (otherDependents * 500);

  @override
  List<Object?> get props => [
        currentStep,
        firstName,
        lastName,
        ssn,
        address,
        cityStateZip,
        filingStatus,
        multipleJobs,
        qualifyingChildren,
        otherDependents,
        otherIncome,
        deductions,
        extraWithholding,
        signature,
        status,
        errorMessage,
      ];
}
