package com.zhentao.vo;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 红娘Excel导出VO
 */
@Data
@ColumnWidth(20)
public class MatchmakerExcelVO implements Serializable {
    
    private static final long serialVersionUID = 1L;
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    
    @ExcelProperty(value = "红娘ID", index = 0)
    private Integer matchmakerId;
    
    @ExcelProperty(value = "姓名", index = 1)
    private String realName;
    
    @ExcelProperty(value = "手机号", index = 2)
    private String phone;
    
    @ExcelProperty(value = "类型", index = 3)
    private String matchmakerType;
    
    @ExcelProperty(value = "等级", index = 4)
    private String level;
    
    @ExcelProperty(value = "成功对数", index = 5)
    private Integer successCouples;
    
    @ExcelProperty(value = "城市", index = 6)
    private String cityName;
    
    @ExcelProperty(value = "状态", index = 7)
    private String status;
    
    @ExcelProperty(value = "创建时间", index = 8)
    private String createdAt;
    
    /**
     * 从Map转换
     */
    public static MatchmakerExcelVO fromMap(java.util.Map<String, Object> map) {
        MatchmakerExcelVO vo = new MatchmakerExcelVO();
        
        vo.setMatchmakerId(getIntValue(map, "matchmaker_id"));
        vo.setRealName(getStringValue(map, "real_name"));
        vo.setPhone(getStringValue(map, "phone"));
        
        // 类型
        Integer type = getIntValue(map, "matchmaker_type");
        vo.setMatchmakerType(type != null && type == 2 ? "全职" : "兼职");
        
        // 等级
        Integer levelVal = getIntValue(map, "level");
        if (levelVal != null) {
            switch (levelVal) {
                case 1: vo.setLevel("青铜"); break;
                case 2: vo.setLevel("白银"); break;
                case 3: vo.setLevel("黄金"); break;
                case 4: vo.setLevel("铂金"); break;
                case 5: vo.setLevel("钻石"); break;
                default: vo.setLevel("未知");
            }
        }
        
        vo.setSuccessCouples(getIntValue(map, "success_couples"));
        vo.setCityName(getStringValue(map, "city_name"));
        
        // 状态
        Integer statusVal = getIntValue(map, "status");
        if (statusVal != null) {
            switch (statusVal) {
                case 1: vo.setStatus("正常"); break;
                case 0: vo.setStatus("禁用"); break;
                case 2: vo.setStatus("离职"); break;
                default: vo.setStatus("未知");
            }
        }
        
        // 时间
        Object createdAt = map.get("created_at");
        if (createdAt instanceof LocalDateTime) {
            vo.setCreatedAt(((LocalDateTime) createdAt).format(FORMATTER));
        } else if (createdAt != null) {
            vo.setCreatedAt(createdAt.toString());
        }
        
        return vo;
    }
    
    private static String getStringValue(java.util.Map<String, Object> map, String key) {
        Object value = map.get(key);
        return value != null ? value.toString() : null;
    }
    
    private static Integer getIntValue(java.util.Map<String, Object> map, String key) {
        Object value = map.get(key);
        if (value instanceof Number) {
            return ((Number) value).intValue();
        }
        return null;
    }
}
