import 'package:equatable/equatable.dart';
import '../../data/datasources/scenario_remote_datasource.dart';

class ScenarioListState extends Equatable {
  final List<ScenarioSummaryModel> scenarios;
  final int currentPage;
  final int totalPages;
  final bool isLoading;
  final bool isLoadingMore;
  final String? error;
  final String? difficultyFilter;
  final String? categoryFilter;
  final String? riskFilter;

  const ScenarioListState({
    this.scenarios = const [],
    this.currentPage = 1,
    this.totalPages = 1,
    this.isLoading = false,
    this.isLoadingMore = false,
    this.error,
    this.difficultyFilter,
    this.categoryFilter,
    this.riskFilter,
  });

  bool get hasMore => currentPage < totalPages;

  ScenarioListState copyWith({
    List<ScenarioSummaryModel>? scenarios,
    int? currentPage,
    int? totalPages,
    bool? isLoading,
    bool? isLoadingMore,
    String? Function()? error,
    String? Function()? difficultyFilter,
    String? Function()? categoryFilter,
    String? Function()? riskFilter,
  }) {
    return ScenarioListState(
      scenarios: scenarios ?? this.scenarios,
      currentPage: currentPage ?? this.currentPage,
      totalPages: totalPages ?? this.totalPages,
      isLoading: isLoading ?? this.isLoading,
      isLoadingMore: isLoadingMore ?? this.isLoadingMore,
      error: error != null ? error() : this.error,
      difficultyFilter: difficultyFilter != null ? difficultyFilter() : this.difficultyFilter,
      categoryFilter: categoryFilter != null ? categoryFilter() : this.categoryFilter,
      riskFilter: riskFilter != null ? riskFilter() : this.riskFilter,
    );
  }

  @override
  List<Object?> get props => [
        scenarios.length,
        currentPage,
        totalPages,
        isLoading,
        isLoadingMore,
        error,
        difficultyFilter,
        categoryFilter,
        riskFilter,
      ];
}

sealed class ScenarioDetailState extends Equatable {
  const ScenarioDetailState();
  @override
  List<Object?> get props => [];
}

class ScenarioDetailLoading extends ScenarioDetailState {
  const ScenarioDetailLoading();
}

class ScenarioDetailLoaded extends ScenarioDetailState {
  final ScenarioDetailModel scenario;
  const ScenarioDetailLoaded(this.scenario);
  @override
  List<Object?> get props => [scenario.id];
}

class ScenarioDetailError extends ScenarioDetailState {
  final String message;
  const ScenarioDetailError(this.message);
  @override
  List<Object?> get props => [message];
}