package cn.iocoder.yudao.module.member.enums;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.map.MapUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author:qjq 订单管理 时间段 时间枚举
 * @Date:2024/4/1 10:54
 */
@AllArgsConstructor
@Getter
public enum TimePeriodEnum {
   /**
    * 早上时间段
    */
   MORNING("00:00:00","9:59:59","2",0,9),
   /**
    * 中午时间段
    */
   MIDDAY("10:00:00","15:59:59","3",10,15),
   /**
    * 晚上时间段
    */
   NIGHT("16:00:00","23:59:59","4",16,23);
   private final String startTime;
   private final String endTime;
   private final String code;
   private final Integer startInt;
   private final Integer endInt;
   public LocalDateTime getStart(){
      LocalDateTime now = LocalDateTimeUtil.now();
      String format = LocalDateTimeUtil.format(now, DatePattern.NORM_DATE_PATTERN);
      format+="T"+startTime;
      return LocalDateTimeUtil.parse(format);
   }
   public LocalDateTime getEnd(){
      LocalDateTime now = LocalDateTimeUtil.now();
      String format = LocalDateTimeUtil.format(now, DatePattern.NORM_DATE_PATTERN);
      format+="T"+endTime;
      return LocalDateTimeUtil.parse(format);
   }
   public Map<String,LocalDateTime> getStartToEnd(){
      LocalDateTime start = this.getStart();
      LocalDateTime end = this.getEnd();
     return MapUtil.builder(new HashMap<String,LocalDateTime>())
              .put("start", start)
              .put("end", end).build();
   }

   public static String getTimePeriod(LocalDateTime localDateTime){
      int hour = localDateTime.getHour();
      if(TimePeriodEnum.MORNING.startInt<=hour && hour<=TimePeriodEnum.MORNING.endInt){
        return CostTypeEnum.MORNING.getCode();
      } else if (TimePeriodEnum.MIDDAY.startInt<=hour && hour<=TimePeriodEnum.MIDDAY.endInt){
         return CostTypeEnum.NOON.getCode();
      }else{
         return CostTypeEnum.NIGHT.getCode();
      }
   }
   public static String getTimeName(LocalDateTime localDateTime){
      int hour = localDateTime.getHour();
      if(TimePeriodEnum.MORNING.startInt<=hour && hour<=TimePeriodEnum.MORNING.endInt){
         return CostTypeEnum.MORNING.getName();
      } else if (TimePeriodEnum.MIDDAY.startInt<=hour && hour<=TimePeriodEnum.MIDDAY.endInt){
         return CostTypeEnum.NOON.getName();
      }else{
         return CostTypeEnum.NIGHT.getName();
      }
   }

}
