import 'package:injectable/injectable.dart';
import 'package:dartz/dartz.dart';
import 'package:equatable/equatable.dart';
import '../entities/dashboard_entity.dart';
import '../repositories/dashboard_repository.dart';
import '../../../../core/error/failures.dart';
import '../../../../core/usecases/usecase.dart';

@injectable
class GetDashboardData implements UseCase<DashboardEntity, GetDashboardDataParams> {
  final DashboardRepository repository;

  GetDashboardData(this.repository);

  @override
  Future<Either<Failure, DashboardEntity>> call(GetDashboardDataParams params) async {
    return await repository.getDashboardData(
      params.organizationId,
      params.userId,
      useGlobalDashboard: params.useGlobalDashboard,
    );
  }
}

class GetDashboardDataParams extends Equatable {
  final String organizationId;
  final String userId;
  final bool useGlobalDashboard;

  const GetDashboardDataParams({
    required this.organizationId,
    required this.userId,
    this.useGlobalDashboard = false,
  });

  @override
  List<Object> get props => [organizationId, userId, useGlobalDashboard];
}

@injectable
class GetDashboardStats implements UseCase<DashboardStatsEntity, GetDashboardStatsParams> {
  final DashboardRepository repository;

  GetDashboardStats(this.repository);

  @override
  Future<Either<Failure, DashboardStatsEntity>> call(GetDashboardStatsParams params) async {
    return await repository.getDashboardStats(
      params.organizationId,
      params.userId,
    );
  }
}

class GetDashboardStatsParams extends Equatable {
  final String organizationId;
  final String userId;

  const GetDashboardStatsParams({
    required this.organizationId,
    required this.userId,
  });

  @override
  List<Object> get props => [organizationId, userId];
}

@injectable
class GetRecentActivities implements UseCase<List<RecentActivityEntity>, GetRecentActivitiesParams> {
  final DashboardRepository repository;

  GetRecentActivities(this.repository);

  @override
  Future<Either<Failure, List<RecentActivityEntity>>> call(GetRecentActivitiesParams params) async {
    return await repository.getRecentActivities(
      params.organizationId,
      params.userId,
      limit: params.limit,
    );
  }
}

class GetRecentActivitiesParams extends Equatable {
  final String organizationId;
  final String userId;
  final int limit;

  const GetRecentActivitiesParams({
    required this.organizationId,
    required this.userId,
    this.limit = 10,
  });

  @override
  List<Object> get props => [organizationId, userId, limit];
}

@injectable
class GetUpcomingEvents implements UseCase<List<UpcomingEventEntity>, GetUpcomingEventsParams> {
  final DashboardRepository repository;

  GetUpcomingEvents(this.repository);

  @override
  Future<Either<Failure, List<UpcomingEventEntity>>> call(GetUpcomingEventsParams params) async {
    return await repository.getUpcomingEvents(
      params.organizationId,
      params.userId,
      limit: params.limit,
    );
  }
}

class GetUpcomingEventsParams extends Equatable {
  final String organizationId;
  final String userId;
  final int limit;

  const GetUpcomingEventsParams({
    required this.organizationId,
    required this.userId,
    this.limit = 5,
  });

  @override
  List<Object> get props => [organizationId, userId, limit];
}
