import 'package:krow/core/sevices/time_slot_service.dart';

class RoleScheduleEntity {
  final int dayIndex;
  final DateTime startTime;
  final DateTime endTime;

  RoleScheduleEntity(
      {required this.dayIndex, required this.startTime, required this.endTime});

  RoleScheduleEntity copyWith({
    int? dayIndex,
    DateTime? startTime,
    DateTime? endTime,
  }) {
    if (startTime != null) {
      startTime =
          startTime.copyWith(day: this.endTime.day, month: this.endTime.month);
    } else if (endTime != null) {
      endTime = endTime.copyWith(
          day: this.startTime.day, month: this.startTime.month);
    }

    return RoleScheduleEntity(
      dayIndex: dayIndex ?? this.dayIndex,
      startTime: startTime ??
          TimeSlotService.calcTime(
              currentStartTime: this.startTime,
              currentEndTime: this.endTime,
              endTime: endTime ?? this.endTime),
      endTime: endTime ??
          TimeSlotService.calcTime(
              currentStartTime: this.startTime,
              currentEndTime: this.endTime,
              startTime: startTime ?? this.startTime),
    );
  }
}
