import 'package:equatable/equatable.dart';

/// Domain entity representing a shift in the coverage view.
///
/// This is a feature-specific domain entity that encapsulates shift information
/// including scheduling details and assigned workers.
class CoverageShift extends Equatable {
  /// Creates a [CoverageShift].
  const CoverageShift({
    required this.id,
    required this.title,
    required this.location,
    required this.startTime,
    required this.workersNeeded,
    required this.date,
    required this.workers,
  });

  /// The unique identifier for the shift.
  final String id;

  /// The title or role of the shift.
  final String title;

  /// The location where the shift takes place.
  final String location;

  /// The start time of the shift (e.g., "16:00").
  final String startTime;

  /// The number of workers needed for this shift.
  final int workersNeeded;

  /// The date of the shift.
  final DateTime date;

  /// The list of workers assigned to this shift.
  final List<CoverageWorker> workers;

  /// Calculates the coverage percentage for this shift.
  int get coveragePercent {
    if (workersNeeded == 0) return 0;
    return ((workers.length / workersNeeded) * 100).round();
  }

  @override
  List<Object?> get props => <Object?>[
        id,
        title,
        location,
        startTime,
        workersNeeded,
        date,
        workers,
      ];
}

/// Domain entity representing a worker in the coverage view.
///
/// This entity tracks worker status including check-in information.
class CoverageWorker extends Equatable {
  /// Creates a [CoverageWorker].
  const CoverageWorker({
    required this.name,
    required this.status,
    this.checkInTime,
  });

  /// The name of the worker.
  final String name;

  /// The status of the worker ('confirmed', 'late', etc.).
  final String status;

  /// The time the worker checked in, if applicable.
  final String? checkInTime;

  /// Returns true if the worker is checked in.
  bool get isCheckedIn => status == 'confirmed' && checkInTime != null;

  /// Returns true if the worker is en route.
  bool get isEnRoute => status == 'confirmed' && checkInTime == null;

  /// Returns true if the worker is late.
  bool get isLate => status == 'late';

  @override
  List<Object?> get props => <Object?>[name, status, checkInTime];
}

/// Domain entity representing coverage statistics.
///
/// Aggregates coverage metrics for a specific date.
class CoverageStats extends Equatable {
  /// Creates a [CoverageStats].
  const CoverageStats({
    required this.totalNeeded,
    required this.totalConfirmed,
    required this.checkedIn,
    required this.enRoute,
    required this.late,
  });

  /// The total number of workers needed.
  final int totalNeeded;

  /// The total number of confirmed workers.
  final int totalConfirmed;

  /// The number of workers who have checked in.
  final int checkedIn;

  /// The number of workers en route.
  final int enRoute;

  /// The number of late workers.
  final int late;

  /// Calculates the overall coverage percentage.
  int get coveragePercent {
    if (totalNeeded == 0) return 0;
    return ((totalConfirmed / totalNeeded) * 100).round();
  }

  @override
  List<Object?> get props => <Object?>[
        totalNeeded,
        totalConfirmed,
        checkedIn,
        enRoute,
        late,
      ];
}
