// SPDX-FileCopyrightText: 2026 FocusFlow contributors
// SPDX-License-Identifier: AGPL-3.0-only

part of '../today_screen_models.dart';

/// Presentation model for the compact Today screen.
class TodayScreenData {
  /// Creates Today screen data.
  const TodayScreenData({
    required this.dateLabel,
    required this.timelineRange,
    required this.cards,
    this.timeZoneOffset = Duration.zero,
    this.requiredBanner,
  });

  /// Creates an empty Today screen model for [dateLabel].
  factory TodayScreenData.empty({
    required String dateLabel,
    Duration timeZoneOffset = Duration.zero,
  }) {
    return TodayScreenData(
      dateLabel: dateLabel,
      timelineRange: defaultRange,
      cards: const [],
      timeZoneOffset: timeZoneOffset,
    );
  }

  /// Maps scheduler core [TodayState] into UI presentation data.
  factory TodayScreenData.fromTodayState(
    TodayState state, {
    required DateTime now,
    Duration timeZoneOffset = Duration.zero,
  }) {
    final cards = [
      for (final item in state.timelineItems)
        TimelineCardModel.fromItem(
          item,
          now: now,
          timeZoneOffset: timeZoneOffset,
        ),
    ];
    final nextRequired = state.nextRequiredItem;
    return TodayScreenData(
      dateLabel: _dateLabel(state.date),
      timelineRange: defaultRange,
      requiredBanner: nextRequired == null
          ? null
          : RequiredBannerModel(
              timelineCardId: nextRequired.id,
              title: nextRequired.item.displayTitle,
              timeText: _formatTime(
                nextRequired.start,
                timeZoneOffset: timeZoneOffset,
              ),
            ),
      cards: List<TimelineCardModel>.unmodifiable(cards),
      timeZoneOffset: timeZoneOffset,
    );
  }

  /// Default visible range for the compact timeline.
  static const defaultRange = TimelineRangeModel(
    startMinutes: 0,
    endMinutes: 24 * 60,
  );

  /// Display-ready date label.
  final String dateLabel;

  /// Optional next-required-task banner model.
  final RequiredBannerModel? requiredBanner;

  /// Visible timeline range.
  final TimelineRangeModel timelineRange;

  /// UI-local offset used for wall-clock timeline labels and positions.
  final Duration timeZoneOffset;

  /// Timeline cards to render.
  final List<TimelineCardModel> cards;
}
