import 'package:intl/intl.dart';
import '../../entities/shifts/shift.dart';

/// Adapter for Shift related data.
class ShiftAdapter {
  /// Maps application data to a Shift entity.
  /// 
  /// This method handles the common mapping logic used across different
  /// repositories when converting application data from Data Connect to
  /// domain Shift entities.
  static Shift fromApplicationData({
    required String shiftId,
    required String roleId,
    required String roleName,
    required String businessName,
    String? companyLogoUrl,
    required double costPerHour,
    String? shiftLocation,
    required String teamHubName,
    DateTime? shiftDate,
    DateTime? startTime,
    DateTime? endTime,
    DateTime? createdAt,
    required String status,
    String? description,
    int? durationDays,
    required int count,
    int? assigned,
    String? eventName,
    bool hasApplied = false,
  }) {
    final String orderName = (eventName ?? '').trim().isNotEmpty
        ? eventName!
        : businessName;
    final String title = '$roleName - $orderName';

    return Shift(
      id: shiftId,
      roleId: roleId,
      title: title,
      clientName: businessName,
      logoUrl: companyLogoUrl,
      hourlyRate: costPerHour,
      location: shiftLocation ?? '',
      locationAddress: teamHubName,
      date: shiftDate?.toIso8601String() ?? '',
      startTime: startTime != null ? DateFormat('HH:mm').format(startTime) : '',
      endTime: endTime != null ? DateFormat('HH:mm').format(endTime) : '',
      createdDate: createdAt?.toIso8601String() ?? '',
      status: status,
      description: description,
      durationDays: durationDays,
      requiredSlots: count,
      filledSlots: assigned ?? 0,
      hasApplied: hasApplied,
    );
  }
}

