part of 'routine_bloc.dart';

class RoutineState extends Equatable {
  final String? loadingSceneId;
  final List<Map<String, dynamic>> ifItems;
  final List<Map<String, dynamic>> thenItems;
  final List<Map<String, String>> availableCards;
  final List<ScenesModel> scenes;
  final List<ScenesModel> automations;
  final Map<String, List<DeviceFunctionData>> selectedFunctions;
  final bool isLoading;
  final String? errorMessage;
  final String? loadScenesErrorMessage;
  final String? loadAutomationErrorMessage;
  final String? routineName;
  final String? selectedIcon;
  final String? searchText;
  final bool isTabToRun;
  final bool isAutomation;
  final String selectedAutomationOperator;
  final EffectiveTime? effectiveTime;
  final String? sceneId;
  final String? automationId;
  final bool? isUpdate;
  final List<AllDevicesModel> devices;
  // final String? automationActionExecutor;
  final bool routineTab;
  final bool createRoutineView;
  final Set<String>? loadingAutomationIds; // Track loading automations

  const RoutineState(
      {this.ifItems = const [],
      this.thenItems = const [],
      this.availableCards = const [],
      this.scenes = const [],
      this.automations = const [],
      this.selectedFunctions = const {},
      this.isLoading = false,
      this.errorMessage,
      this.routineName,
      this.selectedIcon,
      this.loadScenesErrorMessage,
      this.loadAutomationErrorMessage,
      this.searchText,
      this.isTabToRun = false,
      this.isAutomation = false,
      this.selectedAutomationOperator = 'or',
      this.effectiveTime,
      this.sceneId,
      this.automationId,
      this.isUpdate,
      this.loadingAutomationIds = const <String>{}, // Initialize with empty set
      this.loadingSceneId,
      this.devices = const [],
      //  this.automationActionExecutor,
      this.routineTab = false,
      this.createRoutineView = false});

  RoutineState copyWith({
    String? loadingSceneId,
    Set<String>? loadingAutomationIds,
    List<Map<String, dynamic>>? ifItems,
    List<Map<String, dynamic>>? thenItems,
    List<ScenesModel>? scenes,
    List<ScenesModel>? automations,
    Map<String, List<DeviceFunctionData>>? selectedFunctions,
    bool? isLoading,
    String? errorMessage,
    String? routineName,
    String? selectedIcon,
    String? loadAutomationErrorMessage,
    String? loadScenesErrorMessage,
    String? searchText,
    bool? isTabToRun,
    bool? isAutomation,
    String? selectedAutomationOperator,
    EffectiveTime? effectiveTime,
    String? sceneId,
    String? automationId,
    bool? isUpdate,
    List<AllDevicesModel>? devices,
    //  String? automationActionExecutor,
    TextEditingController? nameController,
    bool? routineTab,
    bool? createRoutineView,
  }) {
    return RoutineState(
        loadingSceneId: loadingSceneId,
        loadingAutomationIds: loadingAutomationIds ?? this.loadingAutomationIds,
        ifItems: ifItems ?? this.ifItems,
        thenItems: thenItems ?? this.thenItems,
        scenes: scenes ?? this.scenes,
        automations: automations ?? this.automations,
        selectedFunctions: selectedFunctions ?? this.selectedFunctions,
        isLoading: isLoading ?? this.isLoading,
        errorMessage: errorMessage ?? this.errorMessage,
        routineName: routineName ?? this.routineName,
        selectedIcon: selectedIcon ?? this.selectedIcon,
        loadScenesErrorMessage:
            loadScenesErrorMessage ?? this.loadScenesErrorMessage,
        loadAutomationErrorMessage:
            loadAutomationErrorMessage ?? this.loadAutomationErrorMessage,
        searchText: searchText ?? this.searchText,
        isTabToRun: isTabToRun ?? this.isTabToRun,
        isAutomation: isAutomation ?? this.isAutomation,
        selectedAutomationOperator:
            selectedAutomationOperator ?? this.selectedAutomationOperator,
        effectiveTime: effectiveTime ?? this.effectiveTime,
        sceneId: sceneId ?? this.sceneId,
        automationId: automationId ?? this.automationId,
        isUpdate: isUpdate ?? this.isUpdate,
        devices: devices ?? this.devices,
        //  automationActionExecutor: automationActionExecutor ?? this.automationActionExecutor,
        routineTab: routineTab ?? this.routineTab,
        createRoutineView: createRoutineView ?? this.createRoutineView);
  }

  @override
  List<Object?> get props => [
        loadingAutomationIds,
        ifItems,
        thenItems,
        scenes,
        automations,
        selectedFunctions,
        isLoading,
        errorMessage,
        routineName,
        selectedIcon,
        loadScenesErrorMessage,
        loadAutomationErrorMessage,
        searchText,
        isTabToRun,
        isAutomation,
        selectedAutomationOperator,
        effectiveTime,
        sceneId,
        automationId,
        isUpdate,
        devices,
        //   automationActionExecutor,
        routineTab,
        createRoutineView
      ];
}

class SceneInitial extends RoutineState {}

class SceneLoading extends RoutineState {}

class SceneLoaded extends RoutineState {
  final List<ScenesModel>? scenesOrAutomation;
  const SceneLoaded({this.scenesOrAutomation});
  @override
  List<Object?> get props => [
        scenesOrAutomation,
      ];
}

class SceneError extends RoutineState {
  final String message;

  const SceneError({required this.message});

  @override
  List<Object> get props => [message];
}

class SceneTriggerSuccess extends RoutineState {
  final String sceneName;

  const SceneTriggerSuccess(this.sceneName);

  @override
  List<Object> get props => [sceneName];
}

class UpdateAutomationStatusLoading extends RoutineState {
  const UpdateAutomationStatusLoading();
}
