package com.bonus.canteen.core.utils;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.common.collect.Maps;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Iterator;
import java.util.Map;

public class FlowBeanUtil {
   public static Map<String, String> parseObj2Map(Object obj) {
      JSONObject json = JSONUtil.parseObj(obj);
      Map<String, String> contentMap = Maps.newHashMap();
      Iterator var3 = json.iterator();
      while (var3.hasNext()) {
         Map.Entry<String, Object> next = (Map.Entry) var3.next();
         Object var8 = next.getValue();

         if (var8 instanceof LocalDateTime) {
            LocalDateTime localDateTime = (LocalDateTime) var8;
            contentMap.put(next.getKey(), LocalDateTimeUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss"));
         } else if (var8 instanceof LocalDate) {
            LocalDate localDate = (LocalDate) var8;
            contentMap.put(next.getKey(), LocalDateTimeUtil.format(localDate, "yyyy-MM-dd"));
         } else if (var8 instanceof String) {
            String string = (String) var8;
            contentMap.put(next.getKey(), string);
         } else {
            contentMap.put(next.getKey(), com.alibaba.fastjson.JSONObject.toJSONString(next.getValue()));
         }
      }
//      while(var3.hasNext()) {
//         Map.Entry<String, Object> next = (Map.Entry)var3.next();
//         Object var8 = next.getValue();
//         if (var8 instanceof LocalDateTime localDateTime) {
//            contentMap.put((String)next.getKey(), LocalDateTimeUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss"));
//         } else {
//            var8 = next.getValue();
//            if (var8 instanceof LocalDate localDate) {
//               contentMap.put((String)next.getKey(), LocalDateTimeUtil.format(localDate, "yyyy-MM-dd"));
//            } else {
//               var8 = next.getValue();
//               if (var8 instanceof String string) {
//                  contentMap.put((String)next.getKey(), string);
//               } else {
//                  contentMap.put((String)next.getKey(), com.alibaba.fastjson.JSONObject.toJSONString(next.getValue()));
//               }
//            }
//         }
//      }

      return contentMap;
   }

   public static <T> T convertMapToObject(Map<String, Object> map, Class<T> clazz) {
      ObjectMapper objectMapper = new ObjectMapper();
      objectMapper.registerModule(new JavaTimeModule());
      return objectMapper.convertValue(map, clazz);
   }
}
