import '../../entities/financial/time_card.dart';

/// Adapter for [TimeCard] to map data layer values to domain entity.
class TimeCardAdapter {
  /// Maps primitive values to [TimeCard].
  static TimeCard fromPrimitives({
    required String id,
    required String shiftTitle,
    required String clientName,
    required DateTime date,
    required String startTime,
    required String endTime,
    required double totalHours,
    required double hourlyRate,
    required double totalPay,
    required String status,
    String? location,
  }) {
    return TimeCard(
      id: id,
      shiftTitle: shiftTitle,
      clientName: clientName,
      date: date,
      startTime: startTime,
      endTime: endTime,
      totalHours: totalHours,
      hourlyRate: hourlyRate,
      totalPay: totalPay,
      status: _stringToStatus(status),
      location: location,
    );
  }

  static TimeCardStatus _stringToStatus(String status) {
    switch (status.toUpperCase()) {
      case 'CHECKED_OUT':
      case 'COMPLETED':
        return TimeCardStatus.approved; // Assuming completed = approved for now
      case 'PAID':
        return TimeCardStatus.paid; // If this status exists
      case 'DISPUTED':
        return TimeCardStatus.disputed;
      case 'CHECKED_IN':
      case 'CONFIRMED':
      default:
        return TimeCardStatus.pending;
    }
  }
}
