package com.bonus.canteen.core.common.utils;

import com.bonus.common.houqin.constant.GlobalConstants;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class DateUtil {

    public static List<LocalDate> getLastWeekDate() {
        List<LocalDate> objects = new ArrayList<>();
        LocalDate sunday = LocalDate.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
        LocalDate now = LocalDate.now();
        for (LocalDate date = now; date.isBefore(sunday) || date.isEqual(sunday); date = date.plusDays(1L)) {
            objects.add(date);
        }
        return objects;
    }

    public static List<LocalDate> getLastWeek() {
        List<LocalDate> dates = new ArrayList<>();
        LocalDate now = LocalDate.now();
        for (int i = 0; i < 7; ++i) {
            dates.add(now.plusDays(i));
        }
        return dates;
    }

    public static HashMap<Integer, LocalDate> getDaysInWeekMap() {
        LocalDate now = LocalDate.now();
        HashMap<Integer, LocalDate> dateHashMap = new HashMap<>();
        for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) {
            LocalDate applyWeek = now.plusDays((long) i);
            dateHashMap.put(applyWeek.getDayOfWeek().getValue(), applyWeek);
        }
        return dateHashMap;
    }

}
