package com.ruoyi.zhushi.util;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.*;

public class CalendarGenerator {
    public static void main(String[] args) {
        System.out.println(getMonthDays("2025-07","cn"));
    }
    public static List<DayInfo> getMonthDays(String yearMonth, String language) {
        List<DayInfo> dayInfoList = new ArrayList<>();
        LocalDate startDate = LocalDate.parse(yearMonth + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        int lengthOfMonth = startDate.lengthOfMonth();

        for (int i = 0; i < lengthOfMonth; i++) {
            LocalDate currentDate = startDate.plusDays(i);
            String date = currentDate.toString();
            String dayOfWeek = getCustomDayOfWeek(currentDate.getDayOfWeek(), language);
            int dayNumber = i + 1;

            dayInfoList.add(new DayInfo(date, dayOfWeek, dayNumber));
        }

        return dayInfoList;
    }

    // 自定义星期显示
    private static String getCustomDayOfWeek(DayOfWeek dayOfWeek, String language) {
        String[] cn = {"一", "二", "三", "四", "五", "六", "日"};
        String[] jp = {"月", "火", "水", "木", "金", "土", "日"};

        int index = dayOfWeek.getValue() - 1;
        if ("jp".equalsIgnoreCase(language)) {
            return jp[index];
        } else {
            return cn[index];
        }
    }

    // 内部类：每天信息
    public static class DayInfo {
        private String date;
        private String dayOfWeek;
        private int dayNumber;

        public DayInfo(String date, String dayOfWeek, int dayNumber) {
            this.date = date;
            this.dayOfWeek = dayOfWeek;
            this.dayNumber = dayNumber;
        }

        public String getDate() {
            return date;
        }

        public String getDayOfWeek() {
            return dayOfWeek;
        }

        public int getDayNumber() {
            return dayNumber;
        }

        @Override
        public String toString() {
            return date + " " + dayOfWeek + " Day " + dayNumber;
        }
    }
}
