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 ActivityRegistrationExcelVO 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 Long id;
    
    @ExcelProperty(value = "活动名称", index = 1)
    private String activityName;
    
    @ExcelProperty(value = "用户ID", index = 2)
    private Integer userId;
    
    @ExcelProperty(value = "用户名", index = 3)
    private String userName;
    
    @ExcelProperty(value = "手机号", index = 4)
    private String userPhone;
    
    @ExcelProperty(value = "性别", index = 5)
    private String userGender;
    
    @ExcelProperty(value = "报名时间", index = 6)
    private String registrationTime;
    
    @ExcelProperty(value = "签到状态", index = 7)
    private String checkInStatus;
    
    @ExcelProperty(value = "支付状态", index = 8)
    private String paymentStatus;
    
    @ExcelProperty(value = "创建时间", index = 9)
    private String createdTime;
    
    /**
     * 将实体类转换为ExcelVO
     */
    public static ActivityRegistrationExcelVO fromEntity(com.zhentao.entity.ActivityRegistration registration) {
        ActivityRegistrationExcelVO vo = new ActivityRegistrationExcelVO();
        vo.setId(registration.getId());
        vo.setActivityName(registration.getActivityName());
        vo.setUserId(registration.getUserId());
        vo.setUserName(registration.getUserName());
        vo.setUserPhone(registration.getUserPhone());
        vo.setUserGender(registration.getUserGender() != null && registration.getUserGender() == 1 ? "男" : "女");
        
        if (registration.getRegistrationTime() != null) {
            vo.setRegistrationTime(registration.getRegistrationTime().format(FORMATTER));
        }
        
        // 签到状态：1-已报名，2-已取消，3-已签到
        Integer status = registration.getStatus();
        if (status != null) {
            switch (status) {
                case 1:
                    vo.setCheckInStatus("已报名");
                    break;
                case 2:
                    vo.setCheckInStatus("已取消");
                    break;
                case 3:
                    vo.setCheckInStatus("已签到");
                    break;
                default:
                    vo.setCheckInStatus("未知");
            }
        }
        
        // 支付状态：0-未支付，1-已支付
        Integer paymentStatus = registration.getPaymentStatus();
        if (paymentStatus != null) {
            vo.setPaymentStatus(paymentStatus == 1 ? "已支付" : "未支付");
        } else {
            vo.setPaymentStatus("已支付"); // 默认已支付
        }
        
        if (registration.getCreatedTime() != null) {
            vo.setCreatedTime(registration.getCreatedTime().format(FORMATTER));
        }
        
        return vo;
    }
}

