part of 'task_form_cubit.dart';

enum TaskFormStatus { initial, loading, submitting, success, failure }

class TaskFormState extends Equatable {
  final String? id;
  final TaskFormStatus status;
  final String title;
  final String description;
  final DateTime? dueDate;
  final bool isGlobal;
  final List<String> selectedStaffIds;
  final List<TaskReminderConfig> reminders;
  final Map<String, List<StaffMemberModel>>
  groupedAvailableStaff; // <-- RIPRISTINATO
  final String? errorMessage;

  const TaskFormState({
    this.id,
    this.status = TaskFormStatus.initial,
    this.title = '',
    this.description = '',
    this.dueDate,
    this.isGlobal = false,
    this.selectedStaffIds = const [],
    this.reminders = const [],
    this.groupedAvailableStaff = const {},
    this.errorMessage,
  });

  bool get isFormValid => title.trim().isNotEmpty;

  TaskFormState copyWith({
    String? id,
    TaskFormStatus? status,
    String? title,
    String? description,
    DateTime? dueDate,
    bool? isGlobal,
    List<String>? selectedStaffIds,
    List<TaskReminderConfig>? reminders,
    Map<String, List<StaffMemberModel>>? groupedAvailableStaff,
    String? errorMessage,
  }) {
    return TaskFormState(
      id: id ?? this.id,
      status: status ?? this.status,
      title: title ?? this.title,
      description: description ?? this.description,
      dueDate: dueDate ?? this.dueDate,
      isGlobal: isGlobal ?? this.isGlobal,
      selectedStaffIds: selectedStaffIds ?? this.selectedStaffIds,
      reminders: reminders ?? this.reminders,
      groupedAvailableStaff:
          groupedAvailableStaff ?? this.groupedAvailableStaff,
      errorMessage: errorMessage,
    );
  }

  @override
  List<Object?> get props => [
    id,
    status,
    title,
    description,
    dueDate,
    isGlobal,
    selectedStaffIds,
    reminders,
    groupedAvailableStaff,
    errorMessage,
  ];
}
