// SPDX-FileCopyrightText: 2026 FocusFlow contributors
// SPDX-License-Identifier: AGPL-3.0-only

part of '../scheduler_command_controller.dart';

/// Base state for scheduler command execution in the UI.
sealed class SchedulerCommandState {
  /// Creates a scheduler command state.
  const SchedulerCommandState();
}

/// Indicates that no scheduler command is currently running.
class SchedulerCommandIdle extends SchedulerCommandState {
  /// Creates an idle command state.
  const SchedulerCommandIdle();
}

/// Indicates that a scheduler command is currently running.
class SchedulerCommandRunning extends SchedulerCommandState {
  /// Creates a running command state with a user-facing [label].
  const SchedulerCommandRunning(this.label);

  /// User-facing description of the command in progress.
  final String label;
}

/// Indicates that a scheduler command completed successfully.
class SchedulerCommandSuccess extends SchedulerCommandState {
  /// Creates a success command state with a user-facing [message].
  const SchedulerCommandSuccess(this.message);

  /// User-facing success message.
  final String message;
}

/// Indicates that a scheduler command failed.
class SchedulerCommandFailure extends SchedulerCommandState {
  /// Creates a failure state from an application [failure] or unexpected [error].
  const SchedulerCommandFailure({this.failure, this.error});

  /// Typed application failure returned by the scheduler core.
  final ApplicationFailure? failure;

  /// Unexpected error thrown while running the command.
  final Object? error;

  /// Stable label for display and diagnostics.
  String get codeLabel {
    final typed = failure;
    if (typed != null) {
      return typed.detailCode ?? typed.code.name;
    }
    return 'unexpected';
  }
}
