package com.ruoyi.web.modules.booking.support;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import com.ruoyi.web.modules.booking.domain.vo.AppBookingDateVo;

/**
 * 预约服务 — 近 7 日日期条（含当天）。
 */
public final class AppointmentBookingDateSupport
{
    private static final DateTimeFormatter MM_DD = DateTimeFormatter.ofPattern("MM-dd");

    private static final String[] WEEKDAY_NAMES =
    { "周一", "周二", "周三", "周四", "周五", "周六", "周日" };

    private AppointmentBookingDateSupport()
    {
    }

    public static List<AppBookingDateVo> buildNextSevenDays(LocalDate baseDate)
    {
        LocalDate start = baseDate != null ? baseDate : LocalDate.now();
        List<AppBookingDateVo> list = new ArrayList<>(AppointmentResourceRules.DATE_LIST_SIZE);
        for (int i = 0; i < AppointmentResourceRules.DATE_LIST_SIZE; i++)
        {
            LocalDate day = start.plusDays(i);
            list.add(toVo(day));
        }
        return list;
    }

    static AppBookingDateVo toVo(LocalDate day)
    {
        AppBookingDateVo vo = new AppBookingDateVo();
        int weekday = toWeekdayNumber(day.getDayOfWeek());
        vo.setWeekdayName(WEEKDAY_NAMES[weekday - 1]);
        vo.setWeekday(weekday);
        vo.setDateMmDd(day.format(MM_DD));
        vo.setAppointDate(day.toString());
        return vo;
    }

    /** 周一=1 … 周日=7 */
    public static int toWeekdayNumber(DayOfWeek dayOfWeek)
    {
        return dayOfWeek.getValue();
    }

    public static int toWeekdayNumber(LocalDate date)
    {
        return toWeekdayNumber(date.getDayOfWeek());
    }
}
