import 'package:auto_route/auto_route.dart';
import 'package:flutter/foundation.dart';

@immutable
class CheckListState {
  final List<CheckListItemState> checkListItems;
  final bool isSubmitted;
  final bool isAgree;
  final bool isSubmitEnabled;
  final bool loading;

  const CheckListState({
    this.checkListItems = const [],
    this.isSubmitted = false,
    this.isAgree = false,
    this.loading = false,
    this.isSubmitEnabled = false,
  });

  CheckListState copyWith({
    List<CheckListItemState>? checkListItems,
    bool? isSubmitted,
    bool? isAgree,
    bool? loading,
    bool? isSubmitEnabled,
  }) {
    return CheckListState(
      checkListItems: checkListItems ?? this.checkListItems,
      isSubmitted: isSubmitted ?? this.isSubmitted,
      isAgree: isAgree ?? this.isAgree,
      loading: loading ?? false,
      isSubmitEnabled: isSubmitEnabled ?? this.isSubmitEnabled,
    );
  }

  bool get hasErrors => checkListItems.any((element) => element.error != null);
}

@immutable
class CheckListItemState {
  final String title;
  final String? error;
  final PageRouteInfo? route;

  const CheckListItemState({required this.title, this.route, this.error});
}
