import 'package:intl/intl.dart';

class MealPlanWeek {
  final DateTime start;
  final List<DateTime> days;

  const MealPlanWeek({
    required this.start,
    required this.days,
  });

  factory MealPlanWeek.fromOffset(int offset) {
    final now = DateTime.now();
    final today = DateTime(now.year, now.month, now.day);
    final monday = today.subtract(Duration(days: today.weekday - 1)).add(
          Duration(days: offset * 7),
        );

    return MealPlanWeek(
      start: monday,
      days: List.generate(
        7,
        (index) => DateTime(monday.year, monday.month, monday.day + index),
      ),
    );
  }

  DateTime get end => days.last;

  String get fromIso => isoDate(start);
  String get toIso => isoDate(end);

  String isoDate(DateTime date) => DateFormat('yyyy-MM-dd').format(date);
}