import 'package:equatable/equatable.dart';
import 'package:syncrow_web/utils/constants/app_enum.dart';

class EffectPeriodState extends Equatable {
  final EnumEffectivePeriodOptions selectedPeriod;
  final String selectedDaysBinary;
  final String? customStartTime;
  final String? customEndTime;

  const EffectPeriodState({
    required this.selectedPeriod,
    required this.selectedDaysBinary,
    this.customStartTime,
    this.customEndTime,
  });

  factory EffectPeriodState.initial() {
    return const EffectPeriodState(
      selectedPeriod: EnumEffectivePeriodOptions.allDay,
      selectedDaysBinary: "1111111", // All days selected
      customStartTime: "00:00",
      customEndTime: "23:59",
    );
  }

  EffectPeriodState copyWith({
    EnumEffectivePeriodOptions? selectedPeriod,
    String? selectedDaysBinary,
    String? customStartTime,
    String? customEndTime,
  }) {
    return EffectPeriodState(
      selectedPeriod: selectedPeriod ?? this.selectedPeriod,
      selectedDaysBinary: selectedDaysBinary ?? this.selectedDaysBinary,
      customStartTime: customStartTime ?? this.customStartTime,
      customEndTime: customEndTime ?? this.customEndTime,
    );
  }

  EnumEffectivePeriodOptions getEffectivePeriod() {
    if (customStartTime == '00:00' && customEndTime == '23:59') {
      return EnumEffectivePeriodOptions.allDay;
    } else if (customStartTime == '06:00' && customEndTime == '18:00') {
      return EnumEffectivePeriodOptions.daytime;
    } else if (customStartTime == '18:00' && customEndTime == '06:00') {
      return EnumEffectivePeriodOptions.night;
    } else {
      return EnumEffectivePeriodOptions.custom;
    }
  }

  @override
  List<Object?> get props => [selectedPeriod, selectedDaysBinary, customStartTime, customEndTime];
}
