import 'package:equatable/equatable.dart';
import 'package:krow_domain/krow_domain.dart';

/// Status of the client home dashboard.
enum ClientHomeStatus { initial, loading, success, error }

/// Represents the state of the client home dashboard.
class ClientHomeState extends Equatable {
  final ClientHomeStatus status;
  final List<String> widgetOrder;
  final Map<String, bool> widgetVisibility;
  final bool isEditMode;
  final String? errorMessage;
  final HomeDashboardData dashboardData;
  final List<ReorderItem> reorderItems;
  final String businessName;
  final String? photoUrl;

  const ClientHomeState({
    this.status = ClientHomeStatus.initial,
    this.widgetOrder = const <String>[
      'actions',
      'reorder',
      'coverage',
      'spending',
      'liveActivity',
    ],
    this.widgetVisibility = const <String, bool>{
      'actions': true,
      'reorder': true,
      'coverage': true,
      'spending': true,
      'liveActivity': true,
    },
    this.isEditMode = false,
    this.errorMessage,
    this.dashboardData = const HomeDashboardData(
      weeklySpending: 0.0,
      next7DaysSpending: 0.0,
      weeklyShifts: 0,
      next7DaysScheduled: 0,
      totalNeeded: 0,
      totalFilled: 0,
    ),
    this.reorderItems = const <ReorderItem>[],
    this.businessName = 'Your Company',
    this.photoUrl,
  });

  ClientHomeState copyWith({
    ClientHomeStatus? status,
    List<String>? widgetOrder,
    Map<String, bool>? widgetVisibility,
    bool? isEditMode,
    String? errorMessage,
    HomeDashboardData? dashboardData,
    List<ReorderItem>? reorderItems,
    String? businessName,
    String? photoUrl,
  }) {
    return ClientHomeState(
      status: status ?? this.status,
      widgetOrder: widgetOrder ?? this.widgetOrder,
      widgetVisibility: widgetVisibility ?? this.widgetVisibility,
      isEditMode: isEditMode ?? this.isEditMode,
      errorMessage: errorMessage ?? this.errorMessage,
      dashboardData: dashboardData ?? this.dashboardData,
      reorderItems: reorderItems ?? this.reorderItems,
      businessName: businessName ?? this.businessName,
      photoUrl: photoUrl ?? this.photoUrl,
    );
  }

  @override
  List<Object?> get props => <Object?>[
    status,
    widgetOrder,
    widgetVisibility,
    isEditMode,
    errorMessage,
    dashboardData,
    reorderItems,
    businessName,
    photoUrl,
  ];
}
